sanniassin / react-input-mask

Input masking component for React. Made with attention to UX.
MIT License
2.23k stars 256 forks source link

Does not work Jest snapshot testing #224

Open npi3pak opened 4 years ago

npi3pak commented 4 years ago

Hello, I'm trying to do snapshot testing with Jest and react-test-renderer, but it fails.

I use 3.0.0-alpha.2

code:

import React from 'react';
import renderer from 'react-test-renderer';
import InputMask from 'react-input-mask';

describe("'DateField' component", () => {
  it('should render', () => {
    const tree = renderer
      .create(
        <InputMask mask="99.99.9999">
          <input />
        </InputMask>
      )
      .toJSON();

    expect(tree).toMatchSnapshot();
  });
});

Error:

TypeError: Cannot read property 'addEventListener' of null

       6 |   it('should render', () => {
       7 |     const tree = renderer
    >  8 |       .create(
         |        ^
       9 |         <InputMask
      10 |           // type="text"
      11 |           // alwaysShowMask
iam4x commented 4 years ago

Thanks for your PR @npi3pak, in the meantime I've published a fix on npm =>

mushkin-v commented 8 months ago

Any progress on a fix? This is still an issue and I am getting an error with react-test-renderer and Storybook7!

  TypeError: Cannot read properties of null (reading 'addEventListener')

      at node_modules/react-input-mask/lib/react-input-mask.development.js:219:11
...