fixup! Add toHaveBeenCalledBefore matcher

This commit is contained in:
Damien Cassou
2017-02-20 10:55:23 +01:00
parent 4cfdd06700
commit c93f35fbc8
2 changed files with 48 additions and 6 deletions

View File

@@ -23,12 +23,24 @@ getJasmineRequireObj().toHaveBeenCalledBefore = function(j$) {
return result;
}
result.pass = firstSpy.calls.mostRecent().invocationOrder < latterSpy.calls.mostRecent().invocationOrder;
var latest1stSpyCall = firstSpy.calls.mostRecent().invocationOrder;
var first2ndSpyCall = latterSpy.calls.first().invocationOrder;
result.pass = latest1stSpyCall < first2ndSpyCall;
if (result.pass) {
result.message = 'Expected ' + firstSpy.and.identity() + ' to not have been called before ' + latterSpy.and.identity() + ', but it was';
result.message = 'Expected spy ' + firstSpy.and.identity() + ' to not have been called before spy ' + latterSpy.and.identity() + ', but it was';
} else {
result.message = 'Expected ' + firstSpy.and.identity() + ' to have been called before ' + latterSpy.and.identity();
var first1stSpyCall = firstSpy.calls.first().invocationOrder;
var latest2ndSpyCall = latterSpy.calls.mostRecent().invocationOrder;
if(first1stSpyCall < first2ndSpyCall) {
result.message = 'Expected latest call to spy ' + firstSpy.and.identity() + ' to have been called before first call to spy ' + latterSpy.and.identity() + ' (no interleaved calls)';
} else if (latest2ndSpyCall > latest1stSpyCall) {
result.message = 'Expected first call to spy ' + latterSpy.and.identity() + ' to have been called after latest call to spy ' + firstSpy.and.identity() + ' (no interleaved calls)';
} else {
result.message = 'Expected spy ' + firstSpy.and.identity() + ' to have been called before spy ' + latterSpy.and.identity();
}
}
return result;