Skip to content
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

feature: better support for hooks #122

Merged
merged 1 commit into from
Feb 28, 2019
Merged

feature: better support for hooks #122

merged 1 commit into from
Feb 28, 2019

Conversation

Esemesek
Copy link
Collaborator

@Esemesek Esemesek commented Feb 24, 2019

Summary

Make testing hooks easy.

  • - render calls are wrapped with act
  • - fireEvent calls are wrapped with act
  • - re-exported act from react-test-renderer
  • - added mock act function to prevent brakeable changes
  • - added docs
  • - updated typescript definitions
  • - added tests

Test plan

Unit tests are included in PR.

Fixes #111

@Esemesek Esemesek requested a review from thymikee February 24, 2019 13:26
@hyochan
Copy link

hyochan commented Feb 25, 2019

I was waiting for this! Hope current PR to be merged and released as soon as possible. Thank you for the update @Esemesek.

@Esemesek Esemesek changed the title feature: add support for hooks feature: better support for hooks Feb 25, 2019
@Esemesek
Copy link
Collaborator Author

@hyochan I want it to be checked by @thymikee, but he is on vacations right now. It should be merged in a week time C:

@hyochan
Copy link

hyochan commented Feb 25, 2019

@Esemesek No worry. I can hold that amount of time. Thank you for the detail.

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

This is awesome! Would you be so kind and contribute this back to flow-typed?
https://github.com/flow-typed/flow-typed/blob/master/definitions/npm/react-test-renderer_v16.x.x/test_react-test-renderer-v16.x.x.js

These edits are local-only, so consumers using Flow will start to get errors.

In the meantime I'll merge this, but will wait with the release just a bit

@thymikee thymikee merged commit 11489b0 into master Feb 28, 2019
@thymikee thymikee deleted the Esemesek/act branch February 28, 2019 20:53
@hyochan
Copy link

hyochan commented Mar 4, 2019

@thymikee Thanks. Hope I can get notified when this is released.

@thymikee
Copy link
Member

thymikee commented Mar 4, 2019

It's up in 1.6.0, enjoy :)

@hyochan
Copy link

hyochan commented Mar 7, 2019

@thymikee @Esemesek I am sorry that I may have to ask this question here. I'd really want to know how to test the useEffect as in react-testing-library like in tutorial. How could I achieve things like rerender in react-native-testing-library?

@thymikee
Copy link
Member

thymikee commented Mar 7, 2019

@hyochan it just just work now that all renders are wrapped with act – look at the test file:

const UseEffect = ({ callback }: { callback: Function }) => {
React.useEffect(callback);
return null;
};
const Counter = () => {
const [count, setCount] = React.useState(0);
return (
<Text testID="counter" onPress={() => setCount(count + 1)}>
{count}
</Text>
);
};
test('render should trigger useEffect', () => {
const effectCallback = jest.fn();
render(<UseEffect callback={effectCallback} />);
expect(effectCallback).toHaveBeenCalledTimes(1);
});

Apart from that, we don't have rerender, but we have update method that works the same, see: https://reactjs.org/docs/test-renderer.html#testrendererupdate

@hyochan
Copy link

hyochan commented Mar 7, 2019

@thymikee Thank you so much for your attention! I get it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants