Comparing version 1.3.0 to 1.3.1
@@ -134,2 +134,8 @@ 'use strict'; | ||
/** | ||
* This static attribute can be used to ignore the match | ||
* of a specific argument when using "wasCalledWith". | ||
*/ | ||
Spy.IGNORE = _utils.IGNORE; | ||
/** | ||
* This static method is an alternative way to | ||
@@ -161,3 +167,3 @@ * create a Spy which mocks the an objects attribute. | ||
if (!(method instanceof Function)) { | ||
throw new Error('The object attribute \'' + methodName + '\' ' + ('was: ' + (0, _stringify2.default)(method) + '\n\n') + 'You should only spy on functions!'); | ||
throw new Error('The object attribute \'' + methodName + '\' ' + ('was: ' + (0, _stringify2.default)(method, _utils.JsonStringifyReplacer) + '\n\n') + 'You should only spy on functions!'); | ||
} | ||
@@ -499,3 +505,3 @@ if (method[Symbols.isSpy]) { | ||
} | ||
throw new Error('\n\n' + this[Symbols.name] + ' was considered' + ' to be called with the following arguments:\n\n' + (' --> ' + (0, _stringify2.default)(args) + '\n\n') + 'Actually there were:\n\n' + this.showCallArguments(diffInfo)); | ||
throw new Error('\n\n' + this[Symbols.name] + ' was considered' + ' to be called with the following arguments:\n\n' + (' --> ' + (0, _stringify2.default)(args, _utils.JsonStringifyReplacer) + '\n\n') + 'Actually there were:\n\n' + this.showCallArguments(diffInfo)); | ||
}; | ||
@@ -534,3 +540,3 @@ | ||
if (!errorOccurred) { | ||
throw new Error('\n\n' + this[Symbols.name] + ' was called' + ' unexpectedly with the following arguments:\n\n' + (' --> ' + (0, _stringify2.default)(args) + '\n\n')); | ||
throw new Error('\n\n' + this[Symbols.name] + ' was called' + ' unexpectedly with the following arguments:\n\n' + (' --> ' + (0, _stringify2.default)(args, _utils.JsonStringifyReplacer) + '\n\n')); | ||
} | ||
@@ -651,3 +657,4 @@ }; | ||
for (var i = 0; i < madeCalls.length; i++) { | ||
response += 'call ' + i + ': ' + (0, _stringify2.default)(madeCalls[i].arguments) + '\n'; | ||
var _args = (0, _stringify2.default)(madeCalls[i].arguments, _utils.JsonStringifyReplacer); | ||
response += 'call ' + i + ': ' + _args + '\n'; | ||
if (additionalInformation[i]) { | ||
@@ -654,0 +661,0 @@ response += ' ' + additionalInformation[i] + '\n'; |
@@ -6,4 +6,10 @@ 'use strict'; | ||
}); | ||
exports.JsonStringifyReplacer = exports.IGNORE = exports.objectKeys = exports.forEach = exports.differenceOf = undefined; | ||
var _symbol = require('babel-runtime/core-js/symbol'); | ||
var _symbol2 = _interopRequireDefault(_symbol); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
@@ -60,2 +66,25 @@ * This function takes a handler as second argument to process | ||
/** | ||
* This symbol serves as replacement to ignore any | ||
* inequality and skip further comparisons. | ||
*/ | ||
var IGNORE = (0, _symbol2.default)('__Spy_IGNORE__'); | ||
/** | ||
* This replacer is used to recognize some special | ||
* values as something else than the default would display. | ||
* | ||
* It is used to modify the render behaviour of | ||
* JSON.stringify as long as no other renderer will be used. | ||
*/ | ||
var JsonStringifyReplacer = function JsonStringifyReplacer(k, v) { | ||
if (v === IGNORE) { | ||
return 'Spy.IGNORE'; | ||
} | ||
if (v === undefined) { | ||
return 'UNDEFINED'; | ||
} | ||
return v; | ||
}; | ||
/** | ||
* This function is the internal representation of | ||
@@ -83,2 +112,5 @@ * "differenceOf". It does recursively call itself. | ||
if (a === IGNORE || b === IGNORE) { | ||
return; | ||
} | ||
if (a === b) { | ||
@@ -187,2 +219,4 @@ return; | ||
exports.forEach = forEach; | ||
exports.objectKeys = objectKeys; | ||
exports.objectKeys = objectKeys; | ||
exports.IGNORE = IGNORE; | ||
exports.JsonStringifyReplacer = JsonStringifyReplacer; |
{ | ||
"name": "spy4js", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Use 'new Spy()' to optimize your tests with helpful debug messages.", | ||
@@ -5,0 +5,0 @@ "jest": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
82950
922