question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Testing with Jest

See original GitHub issue

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 and react-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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
Andariuscommented, Dec 9, 2020

FYI this works to mock (https://jestjs.io/docs/en/tutorial-react-native#mock-native-modules-using-jestmock)

jest.mock('@react-native-community/datetimepicker', function () {
    const mockComponent = require('react-native/jest/mockComponent')
    return mockComponent('@react-native-community/datetimepicker')
})
8reactions
sritharIOScommented, Sep 1, 2021

const timePicker = await component.findByTestId(‘dateTimePicker’); fireEvent(timePicker, ‘onChange’, { nativeEvent: { timestamp: ‘01/01/1976’ } });

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest · Delightful JavaScript Testing
Jest is a JavaScript testing framework designed to ensure correctness of any JavaScript codebase. It allows you to write tests with an approachable, ......
Read more >
Jest Tutorial for Beginners: Getting Started With JavaScript ...
Jest is a JavaScript test runner, that is, a JavaScript library for creating, running, and structuring tests. Jest ships as an NPM package,...
Read more >
Jest Tutorial - JavaScript Unit Testing Using Jest Framework
Jest is a Javascript Testing framework built by Facebook. It is primarily designed for React (which is also built by Facebook) based apps...
Read more >
Jest Testing Tutorial: 5 Easy Steps - Testim Blog
1. Install Jest Globally · 2. Create a Sample Project · 3. Add Jest to the Project · 4. Write Your First Test...
Read more >
What Is Jest – A Tutorial on How to Use Jest - LambdaTest
Jest is a testing framework that allows you to write tests in an approachable, familiar, and feature-rich API. Jest provides quick test results...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found