-
-
Notifications
You must be signed in to change notification settings - Fork 424
Testing with Jest #216
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
Comments
@mtakac Can you provide a example of test that you are facing this issue? |
I have the same issue
And I getting the same |
If someone else has this issue , I had to mock it but it works fine for me
I hope that this can help |
I've tried that fix but I got the following error:
With the following code:
Do you have any idea to solve this issue? |
Sorry for the delay @tills98 Try to move
After you imports ( I mean outside of your |
In your setup file: // I use expo v39, therefore I use `@react-native-community/datetimepicker`
jest.mock('@react-native-community/datetimepicker', () => {
const React = require('React')
const RealComponent = jest.requireActual(
'@react-native-community/datetimepicker'
)
class Picker extends React.Component {
render () {
return React.createElement('Picker', this.props, this.props.children)
}
}
Picker.propTypes = RealComponent.propTypes
return Picker
}) Your test: const picker = await findByA11yLabel('picker')
fireEvent(picker, 'onChange', null, date)
expect(picker.props.value).toEqual(date) Original solution from @react-native-community/picker |
FYI this works to mock (https://jestjs.io/docs/en/tutorial-react-native#mock-native-modules-using-jestmock)
|
hello 🙂 |
const timePicker = await component.findByTestId('dateTimePicker'); |
🎉 This issue has been resolved in version 6.3.0 🎉 If this package helps you, consider sponsoring us! 🚀 |
Question
I am having hard times trying to figure out how to write tests for forms using the datetime picker component and I couldn't really find any examples online. Wouldn't it be useful to include a simple example in the docs? I am using
jest
andreact-native-testing-library
. The problem is that every time I open the datetime picker in my tests it throws an error:TypeError: this._picker.current.setNativeProps is not a function
.I am not really sure if I can mock this call out or what the recommended approach would be.
The text was updated successfully, but these errors were encountered: