Skip to content

Commit

Permalink
add @testing-library support to the default template
Browse files Browse the repository at this point in the history
  • Loading branch information
Kent C. Dodds committed Oct 25, 2019
1 parent 07ccad7 commit 033a41c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/cra-template/template/src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { render } from '@testing-library/react';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
test('renders welcome heading', () => {
const { getByRole } = render(<App />);
const headingElement = getByRole('heading');
expect(headingElement).toHaveTextContent(/welcome/i);
});
6 changes: 6 additions & 0 deletions packages/react-scripts/scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ module.exports = function(
args = args.concat(['react', 'react-dom']);
}

args.push(
'@testing-library/react',
'@testing-library/jest-dom',
'@testing-library/user-event'
);

// Install template dependencies, and react and react-dom if missing.
if ((!isReactInstalled(appPackage) || templateName) && args.length > 1) {
console.log();
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/node_path/src/setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect'

0 comments on commit 033a41c

Please sign in to comment.