Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Propagate failure to the end
if (!match) {
return false
}
const arg = args[i]
logger.debug(` matcher: ${matcher}`)
logger.debug(` arg: ${arg}`)
// Assert the match for better messaging during a failure
if (assertCall) {
expect(arg).toEqual(matcher)
}
return utils.equals(arg, matcher)
}
class WhenMock {
return list.findIndex(item => equals(item, value)) > -1;
};
toHaveBeenNthCalledWith(nth, ...expected) {
const received = utils.flag(this, 'object')
const nthCall = received.getCall(nth - 1)
this.assert(
equals(nthCall.args, expected),
`expected spy ${nth} to have been called with arguments #{exp}, actual [${
nthCall.args
}]`,
`expected spy ${nth} not to have been called with arguments #{exp}, actual [${
nthCall.args
}]`,
expected
)
},
toHaveReturned() {
calls.some(call => equals(call.returnValue, expected)),
`expected spy to have returned #{exp} at least once`,
toHaveNthReturnedWith(nth, expected) {
const received = utils.flag(this, 'object')
const nthCall = received.getCall(nth - 1)
this.assert(
equals(nthCall.returnValue, expected),
`expected spy ${nth} to have returned #{exp}, actual [${nthCall.args}]`,
`expected spy ${nth} not to have returned #{exp}, actual [${
nthCall.args
}]`,
expected
)
},
toBe(expected) {
calls.some(call => equals(call.args, expected)),
`expected spy to have been called with arguments #{exp} at least once`,
.filter((callMock) => once || callMock.once || !utils.equals(callMock.matchers, matchers))
.concat({ matchers, val, assertCall, once })
this.callMocks = this.callMocks.filter(mock => {
if (mock.once && utils.equals(mock.matchers, matchers) && !removedOneItem) {
removedOneItem = true
return false
}
return true
})
return val