-
-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New matcher: .toHaveBeenCalledBefore(mock) #98
Comments
taken from jestjs/jest#4402 |
Blocked pending internal timestamp support in Jest: jestjs/jest#4866 |
I would like to work on this. Will keep an eye on the pending Jest issue. |
The PR is merged, should I wait for next release of jest? |
@tejasbubane you could work on it now but we will have to sync merging/releasing this matcher with the next release of Jest. We should also probably add a note to the matcher docs that it will only be compatible with |
I am getting:
I am using |
Hey @ChrisCinelli this matcher hasn’t been implemented yet. @tejasbubane jest@22 has landed now do you still want to work on this? If not I can look into getting it added tomorrow 😄 |
Yes, I found out. But I have bad news:
Yield to:
|
To implement |
@tejasbubane @ChrisCinelli I've added and published this matcher in v0.6.0 so I'm going to close this issue. @ChrisCinelli because of the calls to mocks happening in the same event loop the timestamps are identical - as you described. Because of this for this matcher to work it depends on the mock being asynchronous and ran in a different context. For example: const timeout = time => () => new Promise(res => setTimeout(() => res()), time);
it('calls mock1 before mock2', async () => {
const mock1 = jest.fn(timeout(1));
const mock2 = jest.fn(timeout(1));
await mock1();
await mock2();
await mock1();
expect(mock1).toHaveBeenCalledBefore(mock2);
}); |
Wouldn't it be more scalable to implement an API for What if use cases come up for three calls? 1000? |
Hey @benjamin21st feel free to open a new issue and propose the API that you think would be more scalable 😄 |
Feature Request
.toHaveBeenCalledBefore(mock)
Use
.toHaveBeenCalledBefore
when checking if a mock has been called before another mock.The text was updated successfully, but these errors were encountered: