diff --git a/package.json b/package.json
index cc6fe4bb61d..c67293fa9d7 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/packages/cra-template-typescript/template.json b/packages/cra-template-typescript/template.json
index 86eabeff971..9b3c8540d9b 100644
--- a/packages/cra-template-typescript/template.json
+++ b/packages/cra-template-typescript/template.json
@@ -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",
diff --git a/packages/cra-template-typescript/template/src/App.test.tsx b/packages/cra-template-typescript/template/src/App.test.tsx
index a754b201bf9..db597df0fdc 100644
--- a/packages/cra-template-typescript/template/src/App.test.tsx
+++ b/packages/cra-template-typescript/template/src/App.test.tsx
@@ -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(, div);
- ReactDOM.unmountComponentAtNode(div);
+test('renders welcome heading', () => {
+ const { getByText } = render();
+ const linkElement = getByText(/learn react/i);
+ expect(linkElement).toBeInTheDocument();
});
diff --git a/packages/cra-template-typescript/template/src/setupTests.ts b/packages/cra-template-typescript/template/src/setupTests.ts
new file mode 100644
index 00000000000..74b1a275a0e
--- /dev/null
+++ b/packages/cra-template-typescript/template/src/setupTests.ts
@@ -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';
diff --git a/packages/cra-template/template.json b/packages/cra-template/template.json
index 92a4250788e..6c3d03d1b0d 100644
--- a/packages/cra-template/template.json
+++ b/packages/cra-template/template.json
@@ -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"
+ }
}
diff --git a/packages/cra-template/template/src/App.test.js b/packages/cra-template/template/src/App.test.js
index a754b201bf9..4db7ebc25c2 100644
--- a/packages/cra-template/template/src/App.test.js
+++ b/packages/cra-template/template/src/App.test.js
@@ -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(, div);
- ReactDOM.unmountComponentAtNode(div);
+test('renders learn react link', () => {
+ const { getByText } = render();
+ const linkElement = getByText(/learn react/i);
+ expect(linkElement).toBeInTheDocument();
});
diff --git a/packages/cra-template/template/src/setupTests.js b/packages/cra-template/template/src/setupTests.js
new file mode 100644
index 00000000000..74b1a275a0e
--- /dev/null
+++ b/packages/cra-template/template/src/setupTests.js
@@ -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';
diff --git a/tasks/e2e-installs.sh b/tasks/e2e-installs.sh
index f083f2dd09b..79988df9e29 100755
--- a/tasks/e2e-installs.sh
+++ b/tasks/e2e-installs.sh
@@ -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"