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.

React native input mask testing with jest

See original GitHub issue

Even after mocking the react-native-text-input-mask. I am getting following error. Please help make out here I am not performing any operations from test suite just rendering the screen.

This is how I am using TextInput

 <TextInput
        style={{...inputFields}}
        theme={
          screenValidations && screenValidations.dateOfBirthCheck
            ? InputFieldErrorTheme
            : InputFieldTheme
        }
        mode="outlined"
        onChangeText={dateOfBirthText => setDateOfBirth(dateOfBirthText)}
        value={txtDateOfBirth}
        placeholder="dd/mm/yyyy"
        label={Constants.LABELDATEOFBIRTH}
        right={
          <TextInput.Icon name={CalendarIcon} onPress={() => showModal()} />
        }
        render={props => <TextInputMask {...props} mask="[00]/[00]/[0000]" />}
      />
Screen Shot 2021-05-31 at 8 24 52 pm

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
cgaratecommented, Mar 18, 2022

@MikePolen I was struggling with this and tried a bunch of solutions until I ran into this in the Jest docs: https://jestjs.io/docs/tutorial-react-native#mock-native-modules-using-jestmock So I just added the following mock to my jest.setup.js file: jest.mock('react-native-text-input-mask', () => 'TextInputMask') It worked like a charm on my end. Hope it helps.

0reactions
samianccommented, Nov 7, 2022

I’m using input method instead of change and it’s working.

const inputInstance: any = screen.getByTestId('heightInput');

expect(inputInstance.value).toBe('');
await fireEvent.input(inputInstance, {
    target: { value: '178' }
});
expect(inputInstance.value).toBe('1.78');
Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - React native input mask testing with jest - - Bountysource
Even after mocking the react-native-text-input-mask. I am getting following error. Please help make out here I am not performing any operations from test...
Read more >
How to unit test masked input? - Stack Overflow
How to unit test the masked input field using react-testing-library. That component has developed using material ui and react-hook-form.
Read more >
react-input-mask-jest-dom-bug - CodeSandbox
skratchdotskratchdot. Environmentcreate-react-app. Files. public. src. app.js. app.test.js. helper.js. index.js. styles.css. package.json. Dependencies.
Read more >
react-native-text-input-mask - npm package - Snyk
Learn more about react-native-text-input-mask: package health score, popularity, ... Testing. Jest. Make sure to mock the following to jest.setup.js :
Read more >
[Solved]-How to unit test masked input?-Reactjs - appsloveworld
How to unit test a react event handler that contains history.push using Jest and Enzyme? How to unit test Next.js dynamic components? ......
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