mercredi 17 juillet 2019

Fix unit test Error using Jest in React JS

I'm creating a unit test on some code in React. But there is some action that didn't seem to work.

Let say I have a testing.js containing at the begenning:

const images = require.context('../../../media/promotions', true);

This is the unit test i'm trying ( testing.test.js ) :

import React from 'react';
import { shallow } from 'enzyme';

import { Testing } from '../../src/components/Testing';




let wrapper, instance;

beforeAll(() => {
    wrapper = shallow(
        <Testing />
    );
    instance = wrapper.instance();
});

describe('Testing', () => {
it('renders without crashing', () => {
    expect(wrapper).toMatchSnapshot();
});
})

But the application crushes and this is the error that I get :

TypeError: require.context is not a function

Aucun commentaire:

Enregistrer un commentaire