unexpected-sinon
Advanced tools
Comparing version 7.1.1 to 7.2.0
@@ -52,7 +52,8 @@ Passes if the spy threw the given exception. | ||
invocations( | ||
stub() at theFunction (theFileName:xx:yy), // expected: threw /waat/ | ||
// expected TypeError('wat') to satisfy /waat/ | ||
[ | ||
stub() at theFunction (theFileName:xx:yy) | ||
) | ||
// expected: threw /waat/ | ||
// expected TypeError('wat') to satisfy /waat/ | ||
stub() at theFunction (theFileName:xx:yy) | ||
] | ||
``` |
@@ -19,6 +19,7 @@ Passes if the spy was ever called with obj as its `this` value. | ||
invocations( | ||
spy() at theFunction (theFileName:xx:yy) // expected: was called on {} | ||
// expected spy to be called with {} as this but was called with { spy: spy } | ||
) | ||
[ | ||
spy() at theFunction (theFileName:xx:yy) | ||
// expected: was called on {} | ||
// expected spy to be called with {} as this but was called with { spy: spy } | ||
] | ||
``` | ||
@@ -44,7 +45,8 @@ | ||
invocations( | ||
spy() at theFunction (theFileName:xx:yy), | ||
spy() at theFunction (theFileName:xx:yy) // expected: was called on { spy: spy } | ||
// expected spy to be called with { spy: spy } as this but was called with {} | ||
) | ||
[ | ||
spy() at theFunction (theFileName:xx:yy) | ||
spy() at theFunction (theFileName:xx:yy) | ||
// expected: was called on { spy: spy } | ||
// expected spy to be called with { spy: spy } as this but was called with {} | ||
] | ||
``` |
@@ -25,8 +25,8 @@ Passes if the spy was called exactly the specified number of times. | ||
expected | ||
invocations( | ||
spy( 41, 42 ) at theFunction (theFileName:xx:yy), | ||
spy( 41, 43 ) at theFunction (theFileName:xx:yy), | ||
spy( 41, 44 ) at theFunction (theFileName:xx:yy), | ||
[ | ||
spy( 41, 42 ) at theFunction (theFileName:xx:yy) | ||
spy( 41, 43 ) at theFunction (theFileName:xx:yy) | ||
spy( 41, 44 ) at theFunction (theFileName:xx:yy) | ||
spy( 41, 45 ) at theFunction (theFileName:xx:yy) | ||
) | ||
] | ||
to have length 2 | ||
@@ -33,0 +33,0 @@ expected 4 to be 2 |
@@ -18,3 +18,3 @@ Passes if the spy was called with the provided arguments. | ||
invocations( | ||
[ | ||
spy( | ||
@@ -26,3 +26,3 @@ { foo: 'bar' }, // should equal 'baz' | ||
) at theFunction (theFileName:xx:yy) | ||
) | ||
] | ||
``` | ||
@@ -51,5 +51,5 @@ | ||
invocations( | ||
spy( { foo: 'bar' }, 'baz', 'qux', 'quux' ) at theFunction (theFileName:xx:yy), | ||
spy( { foo: 'bar' }, 'baz', 'qux', 'quux' ) at theFunction (theFileName:xx:yy), | ||
[ | ||
spy( { foo: 'bar' }, 'baz', 'qux', 'quux' ) at theFunction (theFileName:xx:yy) | ||
spy( { foo: 'bar' }, 'baz', 'qux', 'quux' ) at theFunction (theFileName:xx:yy) | ||
spy( | ||
@@ -60,3 +60,3 @@ { foo: 'bar' }, | ||
) at theFunction (theFileName:xx:yy) | ||
) | ||
] | ||
``` | ||
@@ -83,3 +83,3 @@ | ||
invocations( | ||
[ | ||
spy( | ||
@@ -91,3 +91,3 @@ { foo: 'bar' }, | ||
) at theFunction (theFileName:xx:yy) | ||
) | ||
] | ||
``` | ||
@@ -117,5 +117,5 @@ | ||
invocations( | ||
spy( { foo: 'bar' }, 'baz', 'qux' ) at theFunction (theFileName:xx:yy), | ||
spy( { foo: 'bar' }, 'baz', 'qux' ) at theFunction (theFileName:xx:yy), | ||
[ | ||
spy( { foo: 'bar' }, 'baz', 'qux' ) at theFunction (theFileName:xx:yy) | ||
spy( { foo: 'bar' }, 'baz', 'qux' ) at theFunction (theFileName:xx:yy) | ||
spy( | ||
@@ -126,3 +126,3 @@ { foo: 'bar' }, | ||
) at theFunction (theFileName:xx:yy) | ||
) | ||
] | ||
``` |
@@ -36,5 +36,5 @@ Passes if spy was called at least once. | ||
invocations( | ||
[ | ||
spy( 42, 42 ) at theFunction (theFileName:xx:yy) // should be removed | ||
) | ||
] | ||
``` |
@@ -151,3 +151,3 @@ /*global location*/ | ||
if (Array.isArray(stackFrames) && stackFrames.length > 0) { | ||
output.sp().gray('at ' + makePathsRelativeToCwdOrLocation(stackFrames[0].replace(/^\s*(?:at\s+|@)?/, ''))); | ||
output.sp().jsComment('at ' + makePathsRelativeToCwdOrLocation(stackFrames[0].replace(/^\s*(?:at\s+|@)?/, ''))); | ||
} | ||
@@ -177,9 +177,17 @@ return output; | ||
base: 'array-like', | ||
prefix: function (output, value) { | ||
return output.jsFunctionName('invocations').text('('); | ||
delimiter: function (output) { | ||
return output; | ||
}, | ||
suffix: function (output) { | ||
return output.text(')'); | ||
}, | ||
identify: isSpyCalls | ||
identify: isSpyCalls, | ||
inspect: function (spyCalls, depth, output, inspect) { | ||
this.prefix(output); | ||
output.nl() | ||
.indentLines() | ||
.i().block(function (output) { | ||
output.appendItems(spyCalls, '\n'); | ||
}) | ||
.nl() | ||
.outdentLines(); | ||
this.suffix(output); | ||
} | ||
}); | ||
@@ -208,31 +216,105 @@ | ||
var valueType = expect.findTypeOf(value); | ||
var args; | ||
if (value && isSpy(value)) { | ||
value = { spy: value }; | ||
} | ||
var argsValueType = expect.findTypeOf(value.args); | ||
function convertArgumentWithKey(key) { | ||
return objectIs(spyArguments[key], value[key]) ? | ||
expect.it('to be', value[key]) : | ||
convertSinonMatchers(expect, value[key]); | ||
return objectIs(spyArguments[key], value.args[key]) ? | ||
expect.it('to be', value.args[key]) : | ||
convertSinonMatchers(expect, value.args[key]); | ||
} | ||
if (valueType.is('array')) { | ||
args = valueType.getKeys(value).map(convertArgumentWithKey); | ||
} else if (valueType.is('object')) { | ||
args = {}; | ||
valueType.getKeys(value).forEach(function (key) { | ||
args[key] = convertArgumentWithKey(key); | ||
}); | ||
} | ||
var promiseByKey = { | ||
spy: expect.promise(function () { | ||
if (value.spy) { | ||
return expect(subject.proxy, 'to be', value.spy); | ||
} | ||
}), | ||
args: expect.promise(function () { | ||
if (argsValueType.is('array')) { | ||
return expect(spyArguments, 'to satisfy', argsValueType.getKeys(value.args).map(convertArgumentWithKey)); | ||
} else if (argsValueType.is('object')) { | ||
var argsSpec = {}; | ||
argsValueType.getKeys(value.args).forEach(function (key) { | ||
argsSpec[key] = convertArgumentWithKey(key); | ||
}); | ||
return expect(spyArguments, 'to satisfy', argsSpec); | ||
} | ||
}), | ||
threw: expect.promise(function () { | ||
if (value.hasOwnProperty('threw')) { | ||
return expect(subject.exception, 'to satisfy', value.threw); | ||
} else if (value.hasOwnProperty('exception')) { | ||
return expect(subject.exception, 'to satisfy', value.exception); | ||
} | ||
}), | ||
returned: expect.promise(function () { | ||
if (value.hasOwnProperty('returned')) { | ||
return expect(subject.returnValue, 'to satisfy', value.returned); | ||
} else if (value.hasOwnProperty('returnValue')) { | ||
return expect(subject.returnValue, 'to satisfy', value.returnValue); | ||
} | ||
}), | ||
'this': expect.promise(function () { | ||
if (value.hasOwnProperty('this')) { | ||
return expect(subject.thisValue, 'to satisfy', value['this']); | ||
} else if (value.hasOwnProperty('thisValue')) { | ||
return expect(subject.thisValue, 'to satisfy', value.thisValue); | ||
} | ||
return expect.withError(function () { | ||
return expect(spyArguments, 'to satisfy', args); | ||
}, function (err) { | ||
expect.fail({ | ||
diff: function (output) { | ||
var comparison = err.getDiff(output); | ||
subjectType.prefix(output, subject); | ||
output.append(comparison.diff); | ||
subjectType.suffix(output, subject); | ||
comparison.diff = output; | ||
return comparison; | ||
}), | ||
stack: expect.promise(function () { | ||
if (value.stack) { | ||
expect(subject.stack, 'to satisfy', value.stack); | ||
} | ||
}) | ||
}; | ||
return expect.promise.all(promiseByKey).caught(function (err) { | ||
return expect.promise.settle(promiseByKey).then(function () { | ||
err = err.getAllErrors().pop(); | ||
expect.fail({ | ||
diff: function (output) { | ||
subjectType.prefix(output, subject); | ||
var comparison = {}; | ||
var argsDiff = promiseByKey.args && promiseByKey.args.isRejected() && promiseByKey.args.reason().getDiff(output); | ||
var isMatchingSpy = !promiseByKey.spy || promiseByKey.spy.isFulfilled(); | ||
if (argsDiff && isMatchingSpy) { | ||
output.append(argsDiff.diff); | ||
} else { | ||
output.appendInspected(toSpyArguments(subject.args)); | ||
} | ||
subjectType.suffix(output, subject); | ||
var keysWithError = {}; | ||
Object.keys(promiseByKey).forEach(function (key) { | ||
if ((key !== 'args' || !isMatchingSpy) && promiseByKey[key].isRejected()) { | ||
keysWithError[key] = promiseByKey[key].reason(); | ||
} | ||
}); | ||
if (Object.keys(keysWithError).length > 0) { | ||
var annotation = output.clone().annotationBlock(function (output) { | ||
Object.keys(keysWithError).forEach(function (key, i) { | ||
var error = keysWithError[key]; | ||
error.errorMode = 'bubble'; | ||
output.nl(i > 0 ? 2 : 0).error(key + ': ').block(function (output) { | ||
output.appendErrorMessage(error); | ||
}); | ||
}); | ||
}); | ||
if (output.preferredWidth < output.size().width + annotation.size().width) { | ||
output.nl() | ||
.indentLines() | ||
.i().append(annotation); | ||
} else { | ||
output.sp().append(annotation); | ||
} | ||
} | ||
comparison.inline = true; | ||
comparison.diff = output; | ||
return comparison; | ||
} | ||
}); | ||
}); | ||
@@ -277,2 +359,47 @@ }); | ||
expect.addAssertion(['spy', 'array'], 'to have calls satisfying', function (expect, subject, value) { | ||
var spies = subject; | ||
if (!Array.isArray(spies)) { | ||
spies = [ spies ]; | ||
} | ||
var spyCalls = []; | ||
spies.forEach(function (spy) { | ||
Array.prototype.push.apply(spyCalls, spy.getCalls()); | ||
}); | ||
spyCalls.sort(function (a, b) { | ||
return a.callId - b.callId; | ||
}); | ||
var seenSpies = []; | ||
function wrapSpyInObject(obj) { | ||
if (isSpy(obj)) { | ||
seenSpies.push(obj); | ||
return { spy: obj }; | ||
} else { | ||
if (isSpy(obj.spy)) { | ||
seenSpies.push(obj.spy); | ||
} | ||
return obj; | ||
} | ||
} | ||
// Make sure that the array-like to satisfy implementation supports the <spy> => { spy: <spy> } shorthand: | ||
if (Array.isArray(value)) { | ||
value = value.map(wrapSpyInObject); | ||
} else if (value && typeof value === 'object') { | ||
value = Object.keys(value).reduce(function (result, key) { | ||
result[key] = wrapSpyInObject(value[key]); | ||
return result; | ||
}, {}); | ||
} | ||
expect.errorMode = 'nested'; | ||
seenSpies.forEach(function (seenSpy) { | ||
expect(spies, 'to contain', seenSpy); | ||
}); | ||
expect.errorMode = 'default'; | ||
return expect(spyCalls, 'to satisfy', value); | ||
}); | ||
expect.addAssertion('spy', 'was called once', function (expect, subject) { | ||
@@ -352,7 +479,7 @@ var calls = getCalls(subject); | ||
if (this.flags.always) { | ||
return expect(calls, 'to have items satisfying', args); | ||
return expect(calls, 'to have items satisfying', { args: args }); | ||
} else { | ||
var promises = calls.map(function (call) { | ||
return expect.promise(function () { | ||
return expect(call, 'to satisfy', args); | ||
return expect(call, 'to satisfy', { args: args }); | ||
}); | ||
@@ -366,3 +493,3 @@ }); | ||
if (failed) { | ||
return expect(calls, 'to have items satisfying', args); | ||
return expect(calls, 'to have items satisfying', { args: args }); | ||
} | ||
@@ -384,3 +511,3 @@ }); | ||
return expect.promise(function () { | ||
return expect(call, 'not to satisfy', args); | ||
return expect(call, 'not to satisfy', { args: args }); | ||
}); | ||
@@ -393,3 +520,3 @@ }); | ||
if (failed) { | ||
return expect(calls, 'to have items satisfying', 'not to satisfy', args); | ||
return expect(calls, 'to have items satisfying', 'not to satisfy', { args: args }); | ||
} | ||
@@ -396,0 +523,0 @@ }); |
{ | ||
"name": "unexpected-sinon", | ||
"version": "7.1.1", | ||
"version": "7.2.0", | ||
"author": "Sune Sloth Simonsen <sune@we-knowhow.dk>", | ||
@@ -41,5 +41,5 @@ "keywords": [ | ||
"sinon": "1.16.1", | ||
"unexpected": "9.9.0", | ||
"unexpected": "9.12.3", | ||
"unexpected-documentation-site-generator": "2.5.2" | ||
} | ||
} |
@@ -97,7 +97,8 @@ /*global unexpected*/ | ||
"\n" + | ||
"invocations(\n" + | ||
" stub() at theFunction (theFileName:xx:yy), // expected: threw /waat/\n" + | ||
" // expected TypeError('wat') to satisfy /waat/\n" + | ||
"[\n" + | ||
" stub() at theFunction (theFileName:xx:yy)\n" + | ||
")" | ||
" // expected: threw /waat/\n" + | ||
" // expected TypeError('wat') to satisfy /waat/\n" + | ||
" stub() at theFunction (theFileName:xx:yy)\n" + | ||
"]" | ||
); | ||
@@ -127,6 +128,7 @@ } | ||
"\n" + | ||
"invocations(\n" + | ||
" spy() at theFunction (theFileName:xx:yy) // expected: was called on {}\n" + | ||
" // expected spy to be called with {} as this but was called with { spy: spy }\n" + | ||
")" | ||
"[\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" // expected: was called on {}\n" + | ||
" // expected spy to be called with {} as this but was called with { spy: spy }\n" + | ||
"]" | ||
); | ||
@@ -150,7 +152,8 @@ } | ||
"\n" + | ||
"invocations(\n" + | ||
" spy() at theFunction (theFileName:xx:yy),\n" + | ||
" spy() at theFunction (theFileName:xx:yy) // expected: was called on { spy: spy }\n" + | ||
" // expected spy to be called with { spy: spy } as this but was called with {}\n" + | ||
")" | ||
"[\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" // expected: was called on { spy: spy }\n" + | ||
" // expected spy to be called with { spy: spy } as this but was called with {}\n" + | ||
"]" | ||
); | ||
@@ -190,8 +193,8 @@ } | ||
" expected\n" + | ||
" invocations(\n" + | ||
" spy( 41, 42 ) at theFunction (theFileName:xx:yy),\n" + | ||
" spy( 41, 43 ) at theFunction (theFileName:xx:yy),\n" + | ||
" spy( 41, 44 ) at theFunction (theFileName:xx:yy),\n" + | ||
" [\n" + | ||
" spy( 41, 42 ) at theFunction (theFileName:xx:yy)\n" + | ||
" spy( 41, 43 ) at theFunction (theFileName:xx:yy)\n" + | ||
" spy( 41, 44 ) at theFunction (theFileName:xx:yy)\n" + | ||
" spy( 41, 45 ) at theFunction (theFileName:xx:yy)\n" + | ||
" )\n" + | ||
" ]\n" + | ||
" to have length 2\n" + | ||
@@ -229,3 +232,3 @@ " expected 4 to be 2" | ||
"\n" + | ||
"invocations(\n" + | ||
"[\n" + | ||
" spy(\n" + | ||
@@ -237,3 +240,3 @@ " { foo: 'bar' }, // should equal 'baz'\n" + | ||
" ) at theFunction (theFileName:xx:yy)\n" + | ||
")" | ||
"]" | ||
); | ||
@@ -261,5 +264,5 @@ } | ||
"\n" + | ||
"invocations(\n" + | ||
" spy( { foo: 'bar' }, 'baz', 'qux', 'quux' ) at theFunction (theFileName:xx:yy),\n" + | ||
" spy( { foo: 'bar' }, 'baz', 'qux', 'quux' ) at theFunction (theFileName:xx:yy),\n" + | ||
"[\n" + | ||
" spy( { foo: 'bar' }, 'baz', 'qux', 'quux' ) at theFunction (theFileName:xx:yy)\n" + | ||
" spy( { foo: 'bar' }, 'baz', 'qux', 'quux' ) at theFunction (theFileName:xx:yy)\n" + | ||
" spy(\n" + | ||
@@ -270,3 +273,3 @@ " { foo: 'bar' },\n" + | ||
" ) at theFunction (theFileName:xx:yy)\n" + | ||
")" | ||
"]" | ||
); | ||
@@ -291,3 +294,3 @@ } | ||
"\n" + | ||
"invocations(\n" + | ||
"[\n" + | ||
" spy(\n" + | ||
@@ -299,3 +302,3 @@ " { foo: 'bar' },\n" + | ||
" ) at theFunction (theFileName:xx:yy)\n" + | ||
")" | ||
"]" | ||
); | ||
@@ -323,5 +326,5 @@ } | ||
"\n" + | ||
"invocations(\n" + | ||
" spy( { foo: 'bar' }, 'baz', 'qux' ) at theFunction (theFileName:xx:yy),\n" + | ||
" spy( { foo: 'bar' }, 'baz', 'qux' ) at theFunction (theFileName:xx:yy),\n" + | ||
"[\n" + | ||
" spy( { foo: 'bar' }, 'baz', 'qux' ) at theFunction (theFileName:xx:yy)\n" + | ||
" spy( { foo: 'bar' }, 'baz', 'qux' ) at theFunction (theFileName:xx:yy)\n" + | ||
" spy(\n" + | ||
@@ -332,3 +335,3 @@ " { foo: 'bar' },\n" + | ||
" ) at theFunction (theFileName:xx:yy)\n" + | ||
")" | ||
"]" | ||
); | ||
@@ -375,5 +378,5 @@ } | ||
"\n" + | ||
"invocations(\n" + | ||
"[\n" + | ||
" spy( 42, 42 ) at theFunction (theFileName:xx:yy) // should be removed\n" + | ||
")" | ||
"]" | ||
); | ||
@@ -380,0 +383,0 @@ } |
@@ -38,6 +38,6 @@ /*global describe, it, beforeEach, sinon, unexpected*/ | ||
"\n" + | ||
"invocations(\n" + | ||
" spy( 42, { foo: 'bar' } ) at theFunction (theFileName:xx:yy), // should be removed\n" + | ||
"[\n" + | ||
" spy( 42, { foo: 'bar' } ) at theFunction (theFileName:xx:yy) // should be removed\n" + | ||
" spy( 'baz' ) at theFunction (theFileName:xx:yy) // should be removed\n" + | ||
")" | ||
"]" | ||
); | ||
@@ -64,3 +64,7 @@ }); | ||
"expected spy was called once\n" + | ||
" expected invocations( spy( 42, { foo: \'bar\' } ) at theFunction (theFileName:xx:yy), spy( \'baz\' ) at theFunction (theFileName:xx:yy) )\n" + | ||
" expected\n" + | ||
" [\n" + | ||
" spy( 42, { foo: 'bar' } ) at theFunction (theFileName:xx:yy)\n" + | ||
" spy( 'baz' ) at theFunction (theFileName:xx:yy)\n" + | ||
" ]\n" + | ||
" to have length 1\n" + | ||
@@ -87,3 +91,7 @@ " expected 2 to be 1"); | ||
}, "to throw exception", "expected spy was called twice\n" + | ||
" expected invocations( spy() at theFunction (theFileName:xx:yy) ) to have length 2\n" + | ||
" expected\n" + | ||
" [\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" ]\n" + | ||
" to have length 2\n" + | ||
" expected 1 to be 2"); | ||
@@ -98,7 +106,7 @@ | ||
" expected\n" + | ||
" invocations(\n" + | ||
" spy() at theFunction (theFileName:xx:yy),\n" + | ||
" spy( 42 ) at theFunction (theFileName:xx:yy),\n" + | ||
" [\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" )\n" + | ||
" spy( 42 ) at theFunction (theFileName:xx:yy)\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" ]\n" + | ||
" to have length 2\n" + | ||
@@ -122,3 +130,8 @@ " expected 3 to be 2"); | ||
"expected spy was called thrice\n" + | ||
" expected invocations( spy() at theFunction (theFileName:xx:yy), spy() at theFunction (theFileName:xx:yy) ) to have length 3\n" + | ||
" expected\n" + | ||
" [\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" ]\n" + | ||
" to have length 3\n" + | ||
" expected 2 to be 3"); | ||
@@ -133,8 +146,8 @@ | ||
" expected\n" + | ||
" invocations(\n" + | ||
" spy() at theFunction (theFileName:xx:yy),\n" + | ||
" spy() at theFunction (theFileName:xx:yy),\n" + | ||
" spy() at theFunction (theFileName:xx:yy),\n" + | ||
" [\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" )\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" ]\n" + | ||
" to have length 3\n" + | ||
@@ -159,3 +172,8 @@ " expected 4 to be 3"); | ||
"expected spy was called times 3\n" + | ||
" expected invocations( spy() at theFunction (theFileName:xx:yy), spy() at theFunction (theFileName:xx:yy) ) to have length 3\n" + | ||
" expected\n" + | ||
" [\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" ]\n" + | ||
" to have length 3\n" + | ||
" expected 2 to be 3"); | ||
@@ -170,8 +188,8 @@ | ||
" expected\n" + | ||
" invocations(\n" + | ||
" spy() at theFunction (theFileName:xx:yy),\n" + | ||
" spy() at theFunction (theFileName:xx:yy),\n" + | ||
" spy() at theFunction (theFileName:xx:yy),\n" + | ||
" [\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" )\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" ]\n" + | ||
" to have length 3\n" + | ||
@@ -271,7 +289,7 @@ " expected 4 to be 3"); | ||
"\n" + | ||
"invocations(\n" + | ||
" spy() at theFunction (theFileName:xx:yy),\n" + | ||
"[\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" spy() at theFunction (theFileName:xx:yy) // expected: was called on { spy: spy }\n" + | ||
" // expected spy to be called with { spy: spy } as this but was called with null\n" + | ||
")"); | ||
"]"); | ||
}); | ||
@@ -301,3 +319,3 @@ }); | ||
"\n" + | ||
"invocations(\n" + | ||
"[\n" + | ||
" spy(\n" + | ||
@@ -313,3 +331,3 @@ " {\n" + | ||
" ) at theFunction (theFileName:xx:yy)\n" + | ||
")"); | ||
"]"); | ||
}); | ||
@@ -333,3 +351,3 @@ }); | ||
"\n" + | ||
"invocations(\n" + | ||
"[\n" + | ||
" spy(\n" + | ||
@@ -339,6 +357,6 @@ " 'something else' // should equal { foo: 'bar' }\n" + | ||
" // missing: expected spy( 'something else' ) at theFunction (theFileName:xx:yy)\n" + | ||
" // to satisfy { 0: { foo: 'bar' }, 1: 'baz', 2: match(truthy) }\n" + | ||
" ) at theFunction (theFileName:xx:yy),\n" + | ||
" // to satisfy { args: { 0: { foo: 'bar' }, 1: 'baz', 2: match(truthy) } }\n" + | ||
" ) at theFunction (theFileName:xx:yy)\n" + | ||
" spy( { foo: 'bar' }, 'baz', true, false ) at theFunction (theFileName:xx:yy)\n" + | ||
")"); | ||
"]"); | ||
}); | ||
@@ -360,5 +378,5 @@ }); | ||
"\n" + | ||
"invocations(\n" + | ||
" spy( 'bar', 'true' ) at theFunction (theFileName:xx:yy) // should not satisfy { 0: 'bar', 1: match(truthy) }\n" + | ||
")"); | ||
"[\n" + | ||
" spy( 'bar', 'true' ) at theFunction (theFileName:xx:yy) // should not satisfy { args: { 0: 'bar', 1: match(truthy) } }\n" + | ||
"]"); | ||
}); | ||
@@ -374,6 +392,6 @@ | ||
"\n" + | ||
"invocations(\n" + | ||
" spy( 'foo' ) at theFunction (theFileName:xx:yy),\n" + | ||
" spy( 'bar', {} ) at theFunction (theFileName:xx:yy) // should not satisfy { 0: 'bar' }\n" + | ||
")"); | ||
"[\n" + | ||
" spy( 'foo' ) at theFunction (theFileName:xx:yy)\n" + | ||
" spy( 'bar', {} ) at theFunction (theFileName:xx:yy) // should not satisfy { args: { 0: 'bar' } }\n" + | ||
"]"); | ||
}); | ||
@@ -396,3 +414,3 @@ }); | ||
"\n" + | ||
"invocations(\n" + | ||
"[\n" + | ||
" spy(\n" + | ||
@@ -404,3 +422,3 @@ " 'foo',\n" + | ||
" ) at theFunction (theFileName:xx:yy)\n" + | ||
")"); | ||
"]"); | ||
}); | ||
@@ -424,4 +442,4 @@ }); | ||
"\n" + | ||
"invocations(\n" + | ||
" spy( 'foo', 'bar', 'baz' ) at theFunction (theFileName:xx:yy),\n" + | ||
"[\n" + | ||
" spy( 'foo', 'bar', 'baz' ) at theFunction (theFileName:xx:yy)\n" + | ||
" spy(\n" + | ||
@@ -433,3 +451,3 @@ " 'foo',\n" + | ||
" ) at theFunction (theFileName:xx:yy)\n" + | ||
")"); | ||
"]"); | ||
}); | ||
@@ -471,3 +489,3 @@ }); | ||
"\n" + | ||
"invocations(\n" + | ||
"[\n" + | ||
" stub() at theFunction (theFileName:xx:yy) // expected: threw { name: 'TypeError' }\n" + | ||
@@ -482,3 +500,3 @@ " // expected Error() to satisfy { name: 'TypeError' }\n" + | ||
" // }\n" + | ||
")"); | ||
"]"); | ||
}); | ||
@@ -505,6 +523,6 @@ }); | ||
"\n" + | ||
"invocations(\n" + | ||
"[\n" + | ||
" stub() at theFunction (theFileName:xx:yy) // expected: threw Error()\n" + | ||
" // expected TypeError() to satisfy Error()\n" + | ||
")"); | ||
"]"); | ||
}); | ||
@@ -539,6 +557,6 @@ }); | ||
"\n" + | ||
"invocations(\n" + | ||
" spy() at theFunction (theFileName:xx:yy),\n" + | ||
"[\n" + | ||
" spy() at theFunction (theFileName:xx:yy)\n" + | ||
" spy() at theFunction (theFileName:xx:yy) // expected: threw\n" + | ||
")"); | ||
"]"); | ||
}); | ||
@@ -567,4 +585,4 @@ }); | ||
"\n" + | ||
"invocations(\n" + | ||
" stub() at theFunction (theFileName:xx:yy),\n" + | ||
"[\n" + | ||
" stub() at theFunction (theFileName:xx:yy)\n" + | ||
" stub() at theFunction (theFileName:xx:yy) // expected: threw { name: 'Error' }\n" + | ||
@@ -579,3 +597,3 @@ " // expected TypeError() to satisfy { name: 'Error' }\n" + | ||
" // }\n" + | ||
")"); | ||
"]"); | ||
}); | ||
@@ -606,10 +624,84 @@ }); | ||
"\n" + | ||
"invocations(\n" + | ||
" stub() at theFunction (theFileName:xx:yy),\n" + | ||
"[\n" + | ||
" stub() at theFunction (theFileName:xx:yy)\n" + | ||
" stub() at theFunction (theFileName:xx:yy) // expected: threw Error()\n" + | ||
" // expected TypeError() to satisfy Error()\n" + | ||
")"); | ||
"]"); | ||
}); | ||
}); | ||
}); | ||
describe('to have calls satisfying', function () { | ||
it('should satisfy against a list of all calls to the specified spies', function () { | ||
var spy2 = sinon.spy(function () { | ||
return 'blah'; | ||
}); | ||
spy2.displayName = 'spy2'; | ||
var obj = { | ||
die: function () { | ||
throw new Error('say what'); | ||
} | ||
}; | ||
sinon.spy(obj, 'die'); | ||
spy('foo', 'bar'); | ||
spy2('quux'); | ||
try { | ||
obj.die(); | ||
} catch (err) {} | ||
spy('baz'); | ||
spy2('yadda'); | ||
spy('baz'); | ||
expect(function () { | ||
expect([spy, spy2, obj.die], 'to have calls satisfying', [ | ||
spy, | ||
{ spy: spy2, args: [ 'quux' ], returned: 'yadda' }, | ||
{ spy: obj.die, threw: /cqwecqw/ }, | ||
{ spy: spy, args: [ 'yadda' ] }, | ||
spy, | ||
spy | ||
]); | ||
}, 'to throw', | ||
"expected [ spy, spy2, die ] to have calls satisfying\n" + | ||
"[\n" + | ||
" spy,\n" + | ||
" { spy: spy2, args: [ 'quux' ], returned: 'yadda' },\n" + | ||
" { spy: die, threw: /cqwecqw/ },\n" + | ||
" { spy: spy, args: [ 'yadda' ] },\n" + | ||
" spy,\n" + | ||
" spy\n" + | ||
"]\n" + | ||
"\n" + | ||
"[\n" + | ||
" spy( 'foo', 'bar' ) at theFunction (theFileName:xx:yy)\n" + | ||
" spy2( 'quux' ) at theFunction (theFileName:xx:yy) // returned: expected 'blah' to equal 'yadda'\n" + | ||
" //\n" + | ||
" // -blah\n" + | ||
" // +yadda\n" + | ||
" die() at theFunction (theFileName:xx:yy) // threw: expected Error('say what') to satisfy /cqwecqw/\n" + | ||
" spy(\n" + | ||
" 'baz' // should equal 'yadda'\n" + | ||
" // -baz\n" + | ||
" // +yadda\n" + | ||
" ) at theFunction (theFileName:xx:yy)\n" + | ||
" spy2( 'yadda' ) at theFunction (theFileName:xx:yy) // spy: expected spy2 to be spy\n" + | ||
" spy( 'baz' ) at theFunction (theFileName:xx:yy)\n" + | ||
"]" | ||
); | ||
}); | ||
it('should complain if the spy list does not contain a spy that is contained by the spec', function () { | ||
var spy2 = sinon.spy(function () { | ||
return 'blah'; | ||
}); | ||
spy2.displayName = 'spy2'; | ||
expect(function () { | ||
expect([spy], 'to have calls satisfying', [ spy, spy2 ]); | ||
}, 'to throw', | ||
"expected [ spy ] to have calls satisfying [ spy, spy2 ]\n" + | ||
" expected [ spy ] to contain spy2" | ||
); | ||
}); | ||
}); | ||
}); |
652346
6119