diff --git a/lib/create-matcher.js b/lib/create-matcher.js index fe32913..8cb704f 100644 --- a/lib/create-matcher.js +++ b/lib/create-matcher.js @@ -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; } diff --git a/lib/create-matcher.test.js b/lib/create-matcher.test.js index d4dda7e..10c6f85 100644 --- a/lib/create-matcher.test.js +++ b/lib/create-matcher.test.js @@ -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";