lundi 26 août 2019

Test case giving error for spinner in React

I am trying to write a test case for :

const Spinner = () => (
    <div className="spinner">
      <Segment>
        <Dimmer active>
          <Loader size='big'>Loading</Loader>
        </Dimmer>
      </Segment>
      </div>
    )

But getting error shown below

I have tried:

import React from 'react';
import ReactDOM from 'react-dom';
import renderer from 'react-test-renderer';
import Spinner from '../components/Spinner';
import { Dimmer, Loader, Segment } from 'semantic-ui-react';

it('renders without crashing', () => {
    const div = document.createElement('div');
    ReactDOM.render(<Spinner />, div);
    ReactDOM.unmountComponentAtNode(div);
});
it('renders correctly', () => {
    const tree = renderer
        .create(
            <div className="spinner">
                <Segment>
                    <Dimmer active>
          <             Loader size='big'>Loading</Loader>
                    </Dimmer>
                </Segment>
            </div>)
        .toJSON();
    expect(tree).toMatchSnapshot();
});

The test fails saying : Error: Uncaught [TypeError: Cannot read property 'setProperty' of undefined] at reportException (/Users/poonawh/gtm-approval-document-generator/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)..... Consider adding an error boundary to your tree to customize error handling behavior.

Ideally the test should pass

Aucun commentaire:

Enregistrer un commentaire