-
Notifications
You must be signed in to change notification settings - Fork 0
Test coverage #1
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
Conversation
… to reflect, fix useMap re-rendering on bad deletes
…ing clearRefs function
…low payload to accept full state
| import { useForceUpdate } from '../src'; | ||
|
|
||
| describe('useForceUpdate', () => { | ||
| test('forces re-render on update', () => { |
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'm assuming the purpose of useForceUpdate is to force rerender of the component that uses it? How will this do that? I think React is smart enough to only update things that rely on state that has been changed. Since only the tick is updating, I don't think the component that uses this hook will rerender.
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.
So this hook is particularly to be used with hooks that require storing data in refs, but still want to cause an update to the component when the ref value is updated as well
You can see this being used in useMap and useSet. Storing either of the two types in a useState variable and then using the set/add methods don't actually propagate changes to the DOM, since React doesn't know the internal value has been updated
That's where we can use the useForceUpdate method in order to force React to update the UI and recognize a change has occurred
I set up a codebox here for example!: https://codesandbox.io/s/blissful-wood-y817w
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.
Ahh okay that makes sense. Definitely out of the scope for this PR but I think useCallback and maybe useReducer could work without the overhead of useForceUpdate. We can revisit this in the future.
|
@joshpensky This is awesome! I'm getting typescript errors in some of the tests, like in It looks like you added the |
|
Also, we used jest-watch-typeahead on MDA to easily run individual files if you're interested! A nice to have for jest |
| @@ -0,0 +1 @@ | |||
| module.exports = require('babel-jest').createTransformer(); | |||
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.
What does createTransformer() do?
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 believe the transformer is what allows Jest to transpile all of our TS code to JS so it can run its tests
I'm not sure if this needs to be explicitly stated in its own file anymore, but it's listed under the TS section for Jest! https://jestjs.io/docs/en/getting-started#using-typescript
Hmm yeah I was getting that before and thought I fixed it :/ I went ahead and removed the Hopefully that should fix it! There's still an open issue on this in the |
bchiang7
left 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.
I definitely need to read this over more than once to understand it all, but from a high level it all looks good!
Would love to take some time to talk over all of this @joshpensky, but I'm sure once there's some documentation it'll be easier for those without context (a.k.a. Brittany who hasn't been in react land for a while) to understand!

Description
Adds test coverage to all hooks
Fixes #3
What This Does
@testing-library/react-hookstestsfolder to hold all hook testsutils/renderHook, a fork of Testing Library's renderer that also includes renderCountHow to Test
npm testStill Needs
useSettest coverageuseStateReducertest coverageuseMultiReftest coverage