Skip to content

First test with enzyme.(Unit test) #1

Open
@cartooncatfish

Description

@cartooncatfish

Test code: app.test.js

import React from 'react';
import ReactDOM from 'react-dom';
import { shallow } from 'enzyme';

import App from './App';

it('renders without crashing', () => {
	const div = document.createElement('div');
	ReactDOM.render(<App />, div);
	ReactDOM.unmountComponentAtNode(div);
});

it('App renders without crashing version 2, test with the enzyme', () => {
	const component = shallow(<App />);
	expect(component.exists()).toEqual(true);
});

Errors:

FAIL  src/App.test.js
  ● App renders without crashing version 2, test with the enzyme

    
          Enzyme Internal Error: Enzyme expects an adapter to be configured, but found none.
          To configure an adapter, you should call `Enzyme.configure({ adapter: new Adapter() })`
          before using any of Enzyme's top level APIs, where `Adapter` is the adapter
          corresponding to the library currently being tested. For example:
    
          import Adapter from 'enzyme-adapter-react-15';
    
          To find out more about this, see http://airbnb.io/enzyme/docs/installation/index.html
      
          
      at validateAdapter (node_modules/enzyme/build/validateAdapter.js:16:11)
      at getAdapter (node_modules/enzyme/build/getAdapter.js:27:36)
      at new ShallowWrapper (node_modules/enzyme/build/ShallowWrapper.js:168:50)
      at shallow (node_modules/enzyme/build/shallow.js:21:10)
      at Object.<anonymous>.it (src/App.test.js:14:40)
      at Promise.resolve.then.el (node_modules/p-map/index.js:46:16)
      at process._tickCallback (internal/process/next_tick.js:109:7)

  ✓ renders without crashing (3ms)
  ✕ App renders without crashing version 2, test with the enzyme (1ms)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 passed, 2 total
Snapshots:   0 total
Time:        0.151s, estimated 1s
Ran all test suites.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions