-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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(mocking): make response error and result not required when delay is infinite #11562
Conversation
@mspiess: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/ |
👷 Deploy request for apollo-client-docs pending review.Visit the deploys page to approve it
|
🦋 Changeset detectedLatest commit: 7bebece The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Hey @mspiess 👋 Appreciate the contribution! Would you be willing to provide some more information on the use case you're solving for and provide some more information about this change? Thanks! |
Hey @jerelmiller 👋 I updated the PR description. |
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.
Hey @mspiess 👋
I think this change makes sense and provides a nice improvement in your tests. Appreciate the additional context on why this change makes sense!
I've got a few minor things for you to look at. I'd love to get this in the next patch or two. Thanks again!
One more thing! Looks like we've got a couple snapshot tests that check the output of that error in |
aef8c7d
to
face112
Compare
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.
Thanks for working on this and pushing those updates! Just took one more look - this is almost ready to merge 👍
request: { | ||
query, | ||
}, | ||
delay: Number.MAX_VALUE, |
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 it turns out, both Number.MAX_VALUE
and Number.MAX_SAFE_INTEGER
will cause the timeout to fire immediately because neither fit into a 32-bit signed integer. (We can tell that it's not doing anything here since the test finishes in less than the default Jest 5000ms timeout without timer mocks.)
The timing itself isn't material to the behavior of this test, but it would be nice to make it accurate to the behavior we'd see in a real test.
With that in mind, would you mind adding a comment about this here and using a random very high number? We can use Jest's timer mock feature and e.g. jest.advanceTimersByTime(2_000_000_000)
here to get the test passing again.
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.
Ah shoot, I forgot about that. Thanks for the reminder @alessbell!
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.
I used a constant named MAXIMUM_DELAY
. Does that provide enough context, or would you prefer a comment?
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.
A short comment above MAXIMUM_DELAY
would be helpful, something like "We've chosen this value as the MAXIMUM_DELAY
since values that don't fit into a 32-bit signed int cause setTimeout to fire immediately"
import { MockLink } from "../mockLink"; | ||
import { execute } from "../../../../link/core/execute"; | ||
|
||
jest.useFakeTimers(); |
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.
We're just missing a useRealTimers
:
jest.useFakeTimers(); | |
beforeAll(() => jest.useFakeTimers()); | |
afterAll(() => jest.useRealTimers()); |
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.
Left two more minor comments, after those changes are pushed up this is good to go 🚀 Appreciate the contribution @mspiess!
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.
Thanks a bunch @mspiess! We'll get this in the next patch which should release sometime next week.
Great! 🎉 Thanks for the reviews and detailed comments @jerelmiller and @alessbell! |
Without the changes in this PR mocks always require a result or an error for a response. However, when an infinite delay is specified, that response is never returned, so it might as well be omitted.
With the changes in this PR omission of
result
anderror
no longer causes an error, when a delay ofInfinity
is specified.