Skip to content

React hooks test case part 3 -- useCallback#2148

Merged
ljharb merged 1 commit into
enzymejs:masterfrom
chenesan:usecallback-test
May 31, 2019
Merged

React hooks test case part 3 -- useCallback#2148
ljharb merged 1 commit into
enzymejs:masterfrom
chenesan:usecallback-test

Conversation

@chenesan

Copy link
Copy Markdown
Contributor

The tests are almost as same as #2144 , but for useCallback.

And I saw that shallow renderer doesn't memoize the callback between two rendering even the dependencies not change. So the test in chenesan@5cc14ba#diff-2e9c9c89f001140a7699819fc2f5d926R1252 will fail and I temporarily skip it. Have opened an issue in react (react/react#15774) . If it's confirmed as a bug of shallow renderer then I'll try to fix it in react side.

`shallow`: Note that the `get same callback when using `useCallback` and rerender with same prop in dependencies` is skipped because react shallow renderer doesn't memoize callback function value. Pending react/react#15774
@chenesan chenesan mentioned this pull request May 30, 2019
14 tasks
@ljharb ljharb added the Tests label May 30, 2019

@ljharb ljharb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since react/react#15774 is a bug, it'd be good to find a way to work around it before the bugfix is available.

Comment thread packages/enzyme-test-suite/test/ReactWrapper-spec.jsx Outdated
Comment thread packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
@ljharb
ljharb force-pushed the usecallback-test branch 2 times, most recently from f7897d4 to 9cc5f44 Compare May 31, 2019 06:22
@ljharb
ljharb merged commit 9cc5f44 into enzymejs:master May 31, 2019
@chenesan

chenesan commented Jun 8, 2019

Copy link
Copy Markdown
Contributor Author

I just sent a PR for this in react/react#15843 ; As for bugfix in enzyme side, I'm not sure what the way is -- inherit ReactShallowRenderer class and override _createDispatcher in https://github.com/facebook/react/blob/master/packages/react-test-renderer/src/ReactShallowRenderer.js#L230 ? That sounds like a big change... but seems a way to fix hooks issue in shallow renderer (for example, useEffect won't work in shallow).

@ljharb

ljharb commented Jun 8, 2019

Copy link
Copy Markdown
Member

We could stub useCallback in the shallow renderer, perhaps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants