Add @testing-library to the default templates (#7881)

This commit is contained in:
Kent C. Dodds
2019-10-29 15:36:55 -06:00
committed by Ian Schmitz
parent 2c45a3cbe4
commit 2de57fe15a
8 changed files with 33 additions and 13 deletions

View File

@@ -20,6 +20,9 @@
"compile:lockfile": "node tasks/compile-lockfile.js"
},
"devDependencies": {
"@testing-library/react": "^9.3.0",
"@testing-library/jest-dom": "^4.2.0",
"@testing-library/user-event": "^7.1.2",
"alex": "^8.0.0",
"eslint": "^6.1.0",
"execa": "1.0.0",

View File

@@ -1,5 +1,8 @@
{
"dependencies": {
"@testing-library/react": "^9.3.0",
"@testing-library/jest-dom": "^4.2.0",
"@testing-library/user-event": "^7.1.2",
"@types/node": "^12.0.0",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",

View File

@@ -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 { getByText } = render(<App />);
const linkElement = getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});

View File

@@ -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';

View File

@@ -1,3 +1,7 @@
{
"dependencies": {}
"dependencies": {
"@testing-library/react": "^9.3.0",
"@testing-library/jest-dom": "^4.2.0",
"@testing-library/user-event": "^7.1.2"
}
}

View File

@@ -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 learn react link', () => {
const { getByText } = render(<App />);
const linkElement = getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});

View File

@@ -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';

View File

@@ -51,7 +51,7 @@ function exists {
# Check for accidental dependencies in package.json
function checkDependencies {
if ! awk '/"dependencies": {/{y=1;next}/},/{y=0; next}y' package.json | \
grep -v -q -E '^\s*"react(-dom|-scripts)?"'; then
grep -v -q -E '^\s*"(@testing-library\/.+)|(react(-dom|-scripts)?)"'; then
echo "Dependencies are correct"
else
echo "There are extraneous dependencies in package.json"
@@ -62,7 +62,7 @@ function checkDependencies {
# Check for accidental dependencies in package.json
function checkTypeScriptDependencies {
if ! awk '/"dependencies": {/{y=1;next}/},/{y=0; next}y' package.json | \
grep -v -q -E '^\s*"(@types\/.+)|typescript|(react(-dom|-scripts)?)"'; then
grep -v -q -E '^\s*"(@testing-library\/.+)|(@types\/.+)|typescript|(react(-dom|-scripts)?)"'; then
echo "Dependencies are correct"
else
echo "There are extraneous dependencies in package.json"