-
Notifications
You must be signed in to change notification settings - Fork 0
React hooks migration #49
base: master
Are you sure you want to change the base?
Conversation
7f7e80e to
1458f41
Compare
cf83fac to
637586f
Compare
0ec00c4 to
8f3bc4e
Compare
8f3bc4e to
8430ff4
Compare
plzen
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.
Could you also cover the scenario when our useContainer hooks reuses another our custom hook. For example, create custom useTheme hook and use it in all places instead getting theme from context. How we should write tests for useContainer in this case?
| jest.spyOn(AppState, 'removeEventListener'); | ||
|
|
||
| describe('useContainer', () => { | ||
| reactRedux.useDispatch = () => dispatch; |
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 think we should move mocking redux to global mocks folder
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.
refactored
| default: jest.fn(() => ({ | ||
| modalType: 'MY_MODAL', | ||
| modalProps: { customProp: 'customProp' }, | ||
| modalProps: {}, |
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.
Please, add { customProp: 'customProp' } to verify that it's mapped properly
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.
fixed
src/views/modal/ConfirmModal/hook.js
Outdated
| theme, | ||
| handleShouldConfirm, | ||
| onModalHide, | ||
| setShouldConfirm, |
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.
You don't use last 2 values in component, why do you need to export them? Also, you test internal implementation of this props, but should test only external
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 don’t use these values in the component, but I use them in the test.
I need to return value, for example, from useState for the ability to test it changing.
https://react-hooks-testing-library.com/usage/basic-hooks#updates
| exports[`Alert component renders correctly closable 1`] = ` | ||
| <Styled(View) | ||
| color="white" | ||
| color="#ededed" |
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.
Could you try to get the same values that is already in snapshots? We will see that nothing was changed in migration from containers to hooks.
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.
fixed
src/views/shared/Alert/hook.js
Outdated
| const useContainer = () => { | ||
| const theme = useContext(ThemeContext); | ||
|
|
||
| const getStyleProps = (type) => { |
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 think you shouldn't use this as functions, can we modify it to return values and use them in component?
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.
Did you mean to return object from custom hook?
return {
theme,
styleProps: {
[ALERT_TYPES.error]: { ... },
[ALERT_TYPES.success]: { ... },
[ALERT_TYPES.info]: { ... },
},
};
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.
refactored
da04e7b to
a83fd8c
Compare
I created In every hook we can use: For testing we can use snapshots |
a83fd8c to
ad9079e
Compare
ad9079e to
a515613
Compare
Uh oh!
There was an error while loading. Please reload this page.