Make calledAfter symetric with calledBefore #1407
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose (TL;DR)
This makes
calledAfter
symetric withcalledBefore
, as I explained in #1398.Background (Problem in detail)
Semantically speaking,
calledAfter
does not do what it says it does.When you say you expect
something
to have beencalledAfter
anotherThing
, you don't care ifsomething
has been called last or not, all you care about is ifsomething
has been called any times afteranotherThing
.This is the way
calledBefore
works. It is not concerned about whether or not the current spy was the first to be called, it just checks if the current spy has been called any times before the passed spy.Solution
I just check if the last call to the current spy (
this
) has happened after the first call to the passed spy (spyFn
) by comparing theircallIds
I also fixed a test which had the incorrect spec for this.
How to verify
npm install
npm test
-> This will run all tests including the modified one with the correct spec