-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
TestRenderer warns if flushThrough is passed the wrong params #12909
TestRenderer warns if flushThrough is passed the wrong params #12909
Conversation
@@ -576,7 +576,9 @@ describe('Profiler', () => { | |||
</React.unstable_Profiler>, | |||
{unstable_isAsync: true}, | |||
); | |||
expect(renderer.unstable_flushThrough(['first'])).toEqual(['Yield:10']); | |||
expect(renderer.unstable_flushThrough(['Yield:10'])).toEqual([ |
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.
This PR caught this (actual) mistake from master.
Details of bundled changes.Comparing: 76e0707...51d563e react-test-renderer
Generated by 🚫 dangerJS |
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.
Looks good. Left some nits on the error messages but in practice I don't think it matters since we probably expect folks to build their own helper on top of this so they get a nicer diff.
for (let i = 0; i < expectedValues.length; i++) { | ||
if (yieldedValues[i] !== expectedValues[i]) { | ||
const error = new Error( | ||
`flushThrough expected to "${(expectedValues[ |
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.
Typo?
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.
Yargh
return []; | ||
yieldedValues = []; | ||
} | ||
if (yieldedValues.length !== expectedValues.length) { |
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.
Isn't the loop below sufficient?
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.
Yeah. I thought this error message might be more readable, but you're right- it's unnecessary.
Maybe we should switch our tests to use a global global.flushThrough = (testRendererRoot, expectedValues) => {
try {
testRendererRoot.unstable_flushThrough(expectedValues);
} catch (e) {
expect(e.actualValues).toEqual(expectedValues);
}
} |
Yeah, maybe... BeforeAfterIn some ways, this error message is better (because of the nice diff coloring) but in other ways, it's worse- because there's no message/context. Just a couple of arrays that don't match. We also have to remember to use it, which we may not. Either way, this change lets us simplify all of the calls like: expect(renderer.unstable_flushThrough([...])).toEqual([...]); Down to: renderer.unstable_flushThrough([...]); Which seems like a win, since we also sometimes forgot to add those |
TestRenderer throws if flushThrough is passed the expected yield values that don't match actual yield values.
This was silently passing before, when it probably should have failed harder (in case we forgot to expect-to-equal).
The resulting test failures now will not be as pretty (wrt diff highlighting) but it's more foolproof.