react-testing-library

Submitted by Lizhe on Mon, 06/11/2018 - 16:27

任意目录下的 *.test.js

__tests__ 目录下的 *.js

 

import React from 'react'
import {renderIntoDocument, cleanup} from 'react-testing-library'
import App from '../App'
import * as jestDom from 'jest-dom'

expect.extend(jestDom)

afterEach(cleanup)

test('react-testing-library works!', () => {
  const {container} = renderIntoDocument(<App name="Jill" />)
  expect(container.firstChild).toHaveTextContent('Hello Jill!')
})
 

 

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(<App name="Lizhe"/>, document.getElementById('root'));
registerServiceWorker();
 

 

 

npm run test XXXXXX.test.js