-
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v4] Enable strict mode #1709
[v4] Enable strict mode #1709
Conversation
3e50fe9
to
6831601
Compare
Fixes #785 |
@@ -34,7 +34,7 @@ describe('<Header />', () => { | |||
const warnSpy = jest.spyOn(console, 'warn'); | |||
mountWithAppProvider(<Header {...mockProps} icon="foo" />); | |||
|
|||
expect(warnSpy).toHaveBeenCalledTimes(1); | |||
expect(warnSpy).toHaveBeenCalled(); |
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.
React.StrictMode
is causing a second render. I'm not sure why, but I don't think it's a huge deal.
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.
It does that intentionally to try and make it side effects obvious as per https://reactjs.org/docs/strict-mode.html#detecting-unexpected-side-effects
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.
6831601
to
194e4b6
Compare
|
||
beforeEach(() => { | ||
consoleSpy = jest.spyOn(console, 'error'); | ||
consoleSpy.mockImplementation(() => {}); |
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.
Silences the error
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.
Which error is that?
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.
The one at the bottom of this file around expect(consoleSpy).toHaveBeenCalledWith(
. This mockImplementation makes it so the error we're deliberately causing does not get output to the console as we expect it to appear.
.storybook/stories-from-readme.js
Outdated
@@ -66,7 +66,9 @@ export function addPlaygroundStory(playgroundModule) { | |||
function AppProviderDecorator(story) { | |||
return ( | |||
<div style={{padding: '8px'}}> | |||
<AppProvider i18n={en}>{story()}</AppProvider> | |||
<React.StrictMode> |
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.
Instead of setting this in the AppProviderDecorator I think we should add a new global decorator to make sure this applies to all stories. (Admittedly currently AppProvider ends up being applied to everything but at some point that might change if we want to pull in stories from places other than the readmes)
Can you revert this and then in .storybook/config.js under the addParameters
call add:
const StrictModeDecorator = story => <React.StrictMode>{story()}</React.StrictMode>;
addDecorator(StrictModeDecorator);
194e4b6
to
1879ddd
Compare
|
||
beforeEach(() => { | ||
consoleSpy = jest.spyOn(console, 'error'); | ||
consoleSpy.mockImplementation(() => {}); |
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.
Which error is that?
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.
Woo, this is a fantastic milestone!
1879ddd
to
b315b8e
Compare
WHY are these changes introduced?
Fixes: #1709 - This will keep us on track in the future 馃