diff --git a/lib/test.js b/lib/test.js index 59f62d5c..78076cdb 100644 --- a/lib/test.js +++ b/lib/test.js @@ -348,7 +348,7 @@ Test.prototype.intercept = function intercept(obj, property) { $push(calls, { type: 'set', success: !!canSet, value: value, args: args, receiver: this }); if (!canSet && strictMode) { - throw new TypeError('Cannot assign to read only property \'' + property + '\' of object \'' + inspect(obj) + '\''); + throw new TypeError('Cannot assign to read only property `' + inspect(property) + '` of object `' + inspect(obj) + '`'); } return value; } diff --git a/test/intercept.js b/test/intercept.js index 1d640a9c..95a9d4fb 100644 --- a/test/intercept.js +++ b/test/intercept.js @@ -43,6 +43,12 @@ tap.test('intercept: output', function (tt) { 'ok ' + ++count + ' undefined is returned from Get with .call', 'ok ' + ++count + ' foo2: nonwritable property throws on Set', 'ok ' + ++count + ' undefined is still returned from Get', + v.hasSymbols ? [ + 'ok ' + ++count + ' nonwritable Symbol property throws on Set', + 'ok ' + ++count + ' undefined is still returned from Get of a Symbol' + ] : [ + 'ok ' + ++count + ' undefined is still returned from Get of a Symbol # SKIP no Symbol support' + ], 'ok ' + ++count + ' throwing get implementation throws', 'ok ' + ++count + ' throwing get implementation throws with .call', 'ok ' + ++count + ' throwing set implementation throws', @@ -166,6 +172,25 @@ tap.test('intercept: output', function (tt) { st.equal(o.foo2, undefined, 'undefined is still returned from Get'); results2.restore(); + if (v.hasSymbols) { + var sym = Symbol('fooSymbol'); + var resultsSymbol = st.intercept( + o, + sym, + { __proto__: null, writable: false }, + true + ); + st.throws( + function () { o[sym] = 42; }, + new RegExp('^TypeError: Cannot assign to read only property `Symbol\\(fooSymbol\\)` of object `' + inspect(o) + '`$'), + 'nonwritable Symbol property throws on Set' + ); + st.equal(o[sym], undefined, 'undefined is still returned from Get of a Symbol'); + resultsSymbol.restore(); + } else { + st.equal(undefined, undefined, 'undefined is still returned from Get of a Symbol', { skip: 'no Symbol support' }); + } + var resultsThrowGet = st.intercept(o, 'fooThrowGet', { get: function () { throw up; } }); st.throws( function () { return o.fooThrowGet; },