Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add @testing-library support to the default template
Closes #6358
  • Loading branch information
Kent C. Dodds committed Oct 25, 2019
commit 033a41c41ca584f69970aecaf4db3c3abed147d1
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'