-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat(expect): add toHaveBeenCalledAfter
and toHaveBeenCalledBefore
utility
#6056
feat(expect): add toHaveBeenCalledAfter
and toHaveBeenCalledBefore
utility
#6056
Conversation
toHaveBeenCalledAfter
and toHaveBeenCalledBefore
utilitytoHaveBeenCalledAfter
and toHaveBeenCalledBefore
utility
packages/expect/src/jest-expect.ts
Outdated
function (resultSpy: MockInstance) { | ||
const expectSpy = getSpy(this) | ||
|
||
const [firstExpectSpyCall] = expectSpy.mock.invocationCallOrder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why first? Shouldn't it be the smallest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the calls are ordered in the table (so the first one is always the smallest), I thought that taking the first was enough, but maybe I'm wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this got lost in notifications. Looks good to me!
d083215
to
0608b91
Compare
✅ Deploy Preview for vitest-dev ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Description
fix #6045
Hello 👋,
This is my first contribution to Vitest so I really appreciate your feedback.
This PR adds two new test APIs:
toHaveBeenCalledBefore
- checks if a spy was called before another spytoHaveBeenCalledAfter
- checks if a spy was called after another spyThe implementation will take a look at the invocation order (first call) of the spies and compare them to determine if the spies were called in the correct order.
I add them to
packages/expect/src/jest-expect.ts
but I'm not sure if this is the best place for them. I also update types but I'm not sure if I did it correctly so I would appreciate your feedback on that.I add related tests to for these new APIs.
Once everything is ok for you, I will add related documentation!
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yaml
unless you introduce a new test example.Tests
pnpm test:ci
.Documentation
pnpm run docs
command.Changesets
feat:
,fix:
,perf:
,docs:
, orchore:
.