Jest error: test suite did not start, how to solve it?

I am testing Jest for reactions and in particular snapshottesting. This is my test:

import React, { Component } from 'react';
import { shallow } from 'enzyme';
import toJson from 'enzyme-to-json';
import Hello from 'hello';

test('if am then return goodmorning', () => {

    const wrapper = shallow(
        <Hello timeofday="am">
            <strong>Hello World!</strong>
        </Hello>
    );

    expect(toJson(wrapper)).toMatchSnapshot();

});

      

Component I am testing:

import React from 'react';

export default class Hello extends React.Component {

    constructor(props) {
        super();
        this.props = props;
        //todo remove
        console.log('testing props', props);
    }

    render() {
        let greet ;

        if (this.props) {
            greet= this.props.timeofday ==='am' ? 'morning' : 'evening'
        }
        return <h1>Good {greet}</h1>
    }
}

      

When I run jest from the command line, I get this error:

    jest

 FAIL  app/components/hello.test.js
  ● Test suite failed to run

    Cannot find module 'hello' from 'hello.test.js'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
      at Object.<anonymous> (app/components/hello.test.js:4:14)

Test Suites: 1 failed, 1 total

      

Why can't I run a joke? what is the problem?

+3


source to share


1 answer


In the test file

import Hello from 'hello';

      

should be changed to



import Hello from './hello';

      

or you can customize the path in the webpack config file.

+2


source







All Articles