Skip to content

Commit

Permalink
fix: ensure nothing mutates the exported 'message'
Browse files Browse the repository at this point in the history
  • Loading branch information
fatso83 committed Mar 26, 2023
1 parent c6acade commit 5f88086
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/create-matcher.js
Expand Up @@ -60,6 +60,13 @@ function createMatcher(expectation, message) {
m.message = `match(${valueToString(expectation)})`;
}

// ensure that nothing mutates the exported message value, ref https://github.com/sinonjs/sinon/issues/2502
Object.defineProperty(m, "message", {
configurable: false,
writable: false,
value: m.message,
});

return m;
}

Expand Down
9 changes: 9 additions & 0 deletions lib/create-matcher.test.js
Expand Up @@ -417,6 +417,15 @@ describe("matcher", function () {
assert(match.test("testing"));
});

it('ensures the "message" property is unconfigurable', function () {
var match = createMatcher(() => true, "something");
assert.equals(match.message, "something");
assert.exception(() => {
match.message = "something else";
});
assert.equals(match.message, "something");
});

describe(".toString", function () {
it("returns message", function () {
var message = "hello sinonMatch";
Expand Down

0 comments on commit 5f88086

Please sign in to comment.