-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
add jest utils #110
Comments
I wanted to add it, but with the API that you suggested it seems like you will need to change global object in mock: RNKeyboardHandler.openKeyboard(state); // state - height, progress <- seems like here you will change a global value that further is consumed by `useKeyboardAnimation` hook And as far as I remember I experimented with it and it had some problems with tests concurrency. The mock will be created once per file, but since you are changing global object and tests are running in parallel there can be a race condition, where one test will change value and will expect to have that value in next describe("keyboard unit tests", () => {
it("should have keyboard height = 0", () => {
const { getByTestId } = render(<SomeComponentWithKeyboardHandler />);
RNKeyboardHandler.setState({height: 0, progress: 0});
expect(getByTestId("keyboardEventsView").toHaveAnimatedStyle({
height: 0,
});
});
it("should have keyboard height = 100", () => {
const { getByTestId } = render(<SomeComponentWithKeyboardHandler />);
RNKeyboardHandler.setState({height: 100, progress: 0.5});
expect(getByTestId("keyboardEventsView").toHaveAnimatedStyle({
height: 100,
});
});
}); Here we have a situation, where two tests are running in parallel, and there might be chances, that If you have ideas how to implement such helper/utils that will be able to mock value per tests - let me know, I will be glad to hear that! For now you can simply mock returned values for necessary hooks - you may find examples here and here. |
Closed due to inactivity. Feel free to re-open this or open a new issue 😊 |
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Hi @kirillzyusko, Thanks a lot for the library. I would like to suggest you implementation of jestUtils, because It would be really great to have possibility to mock keyboard events in jest.
Describe the solution you'd like
A clear and concise description of what you want to happen.
create a mock implementation for opening/closing keyboard events. In jest it will look like this:
Additional context
Add any other context or screenshots about the feature request here.
I have some ideas how to implement this logic and we can contact to discuss it :)
The text was updated successfully, but these errors were encountered: