Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 033a41c

Browse files
author
Kent C. Dodds
committedOct 25, 2019
add @testing-library support to the default template
Closes facebook#6358
1 parent 07ccad7 commit 033a41c

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
2-
import ReactDOM from 'react-dom';
2+
import { render } from '@testing-library/react';
33
import App from './App';
44

5-
it('renders without crashing', () => {
6-
const div = document.createElement('div');
7-
ReactDOM.render(<App />, div);
8-
ReactDOM.unmountComponentAtNode(div);
5+
test('renders welcome heading', () => {
6+
const { getByRole } = render(<App />);
7+
const headingElement = getByRole('heading');
8+
expect(headingElement).toHaveTextContent(/welcome/i);
99
});

‎packages/react-scripts/scripts/init.js

+6
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ module.exports = function(
219219
args = args.concat(['react', 'react-dom']);
220220
}
221221

222+
args.push(
223+
'@testing-library/react',
224+
'@testing-library/jest-dom',
225+
'@testing-library/user-event'
226+
);
227+
222228
// Install template dependencies, and react and react-dom if missing.
223229
if ((!isReactInstalled(appPackage) || templateName) && args.length > 1) {
224230
console.log();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// jest-dom adds custom jest matchers for asserting on DOM nodes.
2+
// allows you to do things like:
3+
// expect(element).toHaveTextContent(/react/i)
4+
// learn more: https://github.com/testing-library/jest-dom
5+
import '@testing-library/jest-dom/extend-expect'

0 commit comments

Comments
 (0)
Please sign in to comment.