mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-01-12 22:46:30 +08:00
Add @testing-library to the default templates (#7881)
This commit is contained in:
committed by
Ian Schmitz
parent
2c45a3cbe4
commit
2de57fe15a
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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';
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
5
packages/cra-template/template/src/setupTests.js
Normal file
5
packages/cra-template/template/src/setupTests.js
Normal 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';
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user