react-native-multi-slider icon indicating copy to clipboard operation
react-native-multi-slider copied to clipboard

Snapshot testing error: Cannot use import statement outside a module

Open M1chaelChen opened this issue 5 years ago • 1 comments

version: master branch

Got SyntaxError: Cannot use import statement outside a module when shallow rendering with react-native-testing-library

Steps to Reproduce

Slider.js

import MultiSlider from '@ptomasroos/react-native-multi-slider';

<MultiSlider
  isMarkersSeparated
  values={prices}
  onValuesChange={values => {
    setPrices(values);
  }}
  min={1}
  max={50}
  sliderLength={windowWidth }
  customMarkerLeft={() => <SliderMarker />}
  customMarkerRight={() => <SliderMarker />}
  customLabel={() => null}
/>

Slider.test.js

import React from 'react';
import { render } from 'react-native-testing-library';
import Slider from '...';

describe('Slider tests', () => {
  test('renders correctly', () => {
    const output = render(
        <Slider />
    );
    expect(output).toMatchSnapshot();
  });
});

Expected Behavior

Snapshot tests pass

Actual Behavior

image

M1chaelChen avatar Feb 11 '20 00:02 M1chaelChen

If anyone else is running into this, I got around it by adding this to transformIgnorePatterns

"transformIgnorePatterns": [
      "node_modules/(?!(jest-)?react-native|@?ptomasroos/react-native-multi-slider|@?react-navigation)"
    ],

CoryFoy avatar Nov 18 '20 17:11 CoryFoy