Skip to content

Commit

Permalink
Make a helper method for extracting an array of spies.
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Aug 5, 2016
1 parent 15af263 commit 05fa5d6
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions lib/unexpected-sinon.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,16 @@
}
});

expect.addAssertion('<spy|array|sinonSandbox> to have calls [exhaustively] satisfying <function>', function (expect, subject, value) {
var spies = subject;
if (expect.subjectType.is('sinonSandbox')) {
spies = subject.fakes;
} else if (!Array.isArray(spies)) {
spies = [ spies ];
function extractSpies(spyOrArrayOrSinonSandbox) {
if (expect.findTypeOf(spyOrArrayOrSinonSandbox).is('sinonSandbox')) {
return spyOrArrayOrSinonSandbox.fakes;
} else {
return Array.isArray(spyOrArrayOrSinonSandbox) ? spyOrArrayOrSinonSandbox : [ spyOrArrayOrSinonSandbox ];
}
}

expect.addAssertion('<spy|array|sinonSandbox> to have calls [exhaustively] satisfying <function>', function (expect, subject, value) {
var spies = extractSpies(subject);
var expectedSpyCallSpecs = recordSpyCalls(spies, value);
var expectedSpyCalls = [];
expectedSpyCallSpecs.forEach(function (expectedSpyCallSpec) {
Expand All @@ -439,12 +442,7 @@
});

expect.addAssertion('<spy|array|sinonSandbox> to have calls [exhaustively] satisfying <array|object>', function (expect, subject, value) {
var spies = subject;
if (expect.subjectType.is('sinonSandbox')) {
spies = subject.fakes;
} else if (!Array.isArray(spies)) {
spies = [ spies ];
}
var spies = extractSpies(subject);
var spyCalls = [];
var isSeenBySpyId = {};
spies.forEach(function (spy) {
Expand Down

0 comments on commit 05fa5d6

Please sign in to comment.