From 332a6d5972733975980d5e0b3e9583927aadf4d1 Mon Sep 17 00:00:00 2001
From: Lidor Avitan <35113398+lidoravitan@users.noreply.github.com>
Date: Mon, 26 Oct 2020 20:59:24 +0200
Subject: [PATCH 01/24] docs: update complex example (#806)
Co-authored-by: Lidor Avitan
---
README.md | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 6bccc9ac..529d5c17 100644
--- a/README.md
+++ b/README.md
@@ -233,7 +233,9 @@ function Login() {
password: passwordInput.value,
}),
})
- .then(r => r.json())
+ .then((r) =>
+ r.json().then((data) => (r.ok ? data : Promise.reject(data)))
+ )
.then(
user => {
setState({loading: false, resolved: true, error: null})
@@ -282,9 +284,10 @@ import {setupServer} from 'msw/node'
import {render, fireEvent, screen} from '@testing-library/react'
import Login from '../login'
+const fakeUserResponse = { token: 'fake_user_token' }
const server = setupServer(
rest.post('/api/login', (req, res, ctx) => {
- return res(ctx.json({token: 'fake_user_token'}))
+ return res(ctx.json(fakeUserResponse))
}),
)
@@ -322,7 +325,7 @@ test('allows the user to login successfully', async () => {
test('handles server exceptions', async () => {
// mock the server error response for this test suite only.
server.use(
- rest.post('/', (req, res, ctx) => {
+ rest.post('/api/login', (req, res, ctx) => {
return res(ctx.status(500), ctx.json({message: 'Internal server error'}))
}),
)
From 50f54b59c621b93463abfe743b2aa68218ad3f63 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Mon, 26 Oct 2020 13:00:20 -0600
Subject: [PATCH 02/24] docs: add lidoravitan as a contributor (#807)
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 1 +
2 files changed, 10 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 58552c8c..0fd4f4ab 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -1194,6 +1194,15 @@
"contributions": [
"code"
]
+ },
+ {
+ "login": "lidoravitan",
+ "name": "Lidor Avitan",
+ "avatar_url": "https://avatars0.githubusercontent.com/u/35113398?v=4",
+ "profile": "https://github.com/lidoravitan",
+ "contributions": [
+ "doc"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 529d5c17..ba9848ea 100644
--- a/README.md
+++ b/README.md
@@ -601,6 +601,7 @@ Thanks goes to these people ([emoji key][emojis]):
Gerrit Alex π»
Karthick Raja π»
Abdelrahman Ashraf π»
+ Lidor Avitan π
From c2806fcc88d488663e0202a45e9c5ff528fb39fc Mon Sep 17 00:00:00 2001
From: Sebastian Silbermann
Date: Thu, 29 Oct 2020 15:06:17 +0100
Subject: [PATCH 03/24] test: Fix node 15 (#809)
---
.travis.yml | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/.travis.yml b/.travis.yml
index eae48ee7..fbe104b8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,12 +7,15 @@ node_js:
- 10.14.2
- 12
- 14
- - node
+ - 15
env:
- REACT_DIST=latest
- REACT_DIST=next
- REACT_DIST=experimental
install:
+ # 7.0.6 fixed CI environments prompting user input.
+ # Can be removed once node15 bumps the shipped npm version.
+ - npm install --global npm@>=7.0.6
- npm install
# as requested by the React team :)
# https://reactjs.org/blog/2019/10/22/react-release-channels.html#using-the-next-channel-for-integration-testing
From 0db811283819fdc9774e36155ff806f44500533c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?=
Date: Thu, 29 Oct 2020 22:08:52 +0100
Subject: [PATCH 04/24] chore: update React imports (#811)
---
README.md | 22 ++++++++++------------
src/__tests__/act.js | 2 +-
src/__tests__/auto-cleanup-skip.js | 2 +-
src/__tests__/auto-cleanup.js | 2 +-
src/__tests__/cleanup.js | 2 +-
src/__tests__/debug.js | 2 +-
src/__tests__/end-to-end.js | 2 +-
src/__tests__/events.js | 2 +-
src/__tests__/multi-base.js | 2 +-
src/__tests__/render.js | 2 +-
src/__tests__/rerender.js | 2 +-
src/__tests__/stopwatch.js | 2 +-
src/act-compat.js | 2 +-
src/pure.js | 2 +-
14 files changed, 23 insertions(+), 25 deletions(-)
diff --git a/README.md b/README.md
index ba9848ea..a43cb5a6 100644
--- a/README.md
+++ b/README.md
@@ -154,7 +154,7 @@ afterAll(() => {
```jsx
// hidden-message.js
-import React from 'react'
+import * as React from 'react'
// NOTE: React Testing Library works well with React Hooks and classes.
// Your tests will be the same regardless of how you write your components.
@@ -184,7 +184,7 @@ export default HiddenMessage
import '@testing-library/jest-dom'
// NOTE: jest-dom adds handy assertions to Jest and is recommended, but not required
-import React from 'react'
+import * as React from 'react'
import {render, fireEvent, screen} from '@testing-library/react'
import HiddenMessage from '../hidden-message'
@@ -209,7 +209,7 @@ test('shows the children when the checkbox is checked', () => {
```jsx
// login.js
-import React from 'react'
+import * as React from 'react'
function Login() {
const [state, setState] = React.useReducer((s, a) => ({...s, ...a}), {
@@ -233,9 +233,7 @@ function Login() {
password: passwordInput.value,
}),
})
- .then((r) =>
- r.json().then((data) => (r.ok ? data : Promise.reject(data)))
- )
+ .then(r => r.json().then(data => (r.ok ? data : Promise.reject(data))))
.then(
user => {
setState({loading: false, resolved: true, error: null})
@@ -276,7 +274,7 @@ export default Login
// again, these first two imports are something you'd normally handle in
// your testing framework configuration rather than importing them in every file.
import '@testing-library/jest-dom'
-import React from 'react'
+import * as React from 'react'
// import API mocking utilities from Mock Service Worker.
import {rest} from 'msw'
import {setupServer} from 'msw/node'
@@ -284,7 +282,7 @@ import {setupServer} from 'msw/node'
import {render, fireEvent, screen} from '@testing-library/react'
import Login from '../login'
-const fakeUserResponse = { token: 'fake_user_token' }
+const fakeUserResponse = {token: 'fake_user_token'}
const server = setupServer(
rest.post('/api/login', (req, res, ctx) => {
return res(ctx.json(fakeUserResponse))
@@ -400,8 +398,8 @@ principles:
`react-dom`.
3. Utility implementations and APIs should be simple and flexible.
-Most importantly, we want React Testing Library to be pretty
-light-weight, simple, and easy to understand.
+Most importantly, we want React Testing Library to be pretty light-weight,
+simple, and easy to understand.
## Docs
@@ -410,8 +408,7 @@ light-weight, simple, and easy to understand.
## Issues
-Looking to contribute? Look for the [Good First Issue][good-first-issue]
-label.
+Looking to contribute? Look for the [Good First Issue][good-first-issue] label.
### π Bugs
@@ -607,6 +604,7 @@ Thanks goes to these people ([emoji key][emojis]):
+
This project follows the [all-contributors][all-contributors] specification.
diff --git a/src/__tests__/act.js b/src/__tests__/act.js
index 97438d77..b60aac37 100644
--- a/src/__tests__/act.js
+++ b/src/__tests__/act.js
@@ -1,4 +1,4 @@
-import React from 'react'
+import * as React from 'react'
import {render, fireEvent, screen} from '../'
test('render calls useEffect immediately', () => {
diff --git a/src/__tests__/auto-cleanup-skip.js b/src/__tests__/auto-cleanup-skip.js
index e5ef35ae..5696d4e3 100644
--- a/src/__tests__/auto-cleanup-skip.js
+++ b/src/__tests__/auto-cleanup-skip.js
@@ -1,4 +1,4 @@
-import React from 'react'
+import * as React from 'react'
let render
beforeAll(() => {
diff --git a/src/__tests__/auto-cleanup.js b/src/__tests__/auto-cleanup.js
index 27debe45..450a6136 100644
--- a/src/__tests__/auto-cleanup.js
+++ b/src/__tests__/auto-cleanup.js
@@ -1,4 +1,4 @@
-import React from 'react'
+import * as React from 'react'
import {render} from '../'
// This just verifies that by importing RTL in an
diff --git a/src/__tests__/cleanup.js b/src/__tests__/cleanup.js
index 4b67814a..6043ae06 100644
--- a/src/__tests__/cleanup.js
+++ b/src/__tests__/cleanup.js
@@ -1,4 +1,4 @@
-import React from 'react'
+import * as React from 'react'
import {render, cleanup} from '../'
test('cleans up the document', () => {
diff --git a/src/__tests__/debug.js b/src/__tests__/debug.js
index 14c0779a..e4e9faa0 100644
--- a/src/__tests__/debug.js
+++ b/src/__tests__/debug.js
@@ -1,4 +1,4 @@
-import React from 'react'
+import * as React from 'react'
import {render, screen} from '../'
beforeEach(() => {
diff --git a/src/__tests__/end-to-end.js b/src/__tests__/end-to-end.js
index cbbf0973..87c70f1b 100644
--- a/src/__tests__/end-to-end.js
+++ b/src/__tests__/end-to-end.js
@@ -1,4 +1,4 @@
-import React from 'react'
+import * as React from 'react'
import {render, waitForElementToBeRemoved, screen} from '../'
const fetchAMessage = () =>
diff --git a/src/__tests__/events.js b/src/__tests__/events.js
index 0e28848f..8a6899af 100644
--- a/src/__tests__/events.js
+++ b/src/__tests__/events.js
@@ -1,4 +1,4 @@
-import React from 'react'
+import * as React from 'react'
import {render, fireEvent} from '../'
const eventTypes = [
diff --git a/src/__tests__/multi-base.js b/src/__tests__/multi-base.js
index 06ad0902..ef5a7e11 100644
--- a/src/__tests__/multi-base.js
+++ b/src/__tests__/multi-base.js
@@ -1,4 +1,4 @@
-import React from 'react'
+import * as React from 'react'
import {render} from '../'
// these are created once per test suite and reused for each case
diff --git a/src/__tests__/render.js b/src/__tests__/render.js
index 4e78afa6..fdc1ff4c 100644
--- a/src/__tests__/render.js
+++ b/src/__tests__/render.js
@@ -1,4 +1,4 @@
-import React from 'react'
+import * as React from 'react'
import ReactDOM from 'react-dom'
import {render, screen} from '../'
diff --git a/src/__tests__/rerender.js b/src/__tests__/rerender.js
index 7cb9156d..f8ea377e 100644
--- a/src/__tests__/rerender.js
+++ b/src/__tests__/rerender.js
@@ -1,4 +1,4 @@
-import React from 'react'
+import * as React from 'react'
import {render} from '../'
test('rerender will re-render the element', () => {
diff --git a/src/__tests__/stopwatch.js b/src/__tests__/stopwatch.js
index 3fe423b1..eeaf395c 100644
--- a/src/__tests__/stopwatch.js
+++ b/src/__tests__/stopwatch.js
@@ -1,4 +1,4 @@
-import React from 'react'
+import * as React from 'react'
import {render, fireEvent, screen} from '../'
class StopWatch extends React.Component {
diff --git a/src/act-compat.js b/src/act-compat.js
index e999ecfe..40ecdab9 100644
--- a/src/act-compat.js
+++ b/src/act-compat.js
@@ -1,4 +1,4 @@
-import React from 'react'
+import * as React from 'react'
import ReactDOM from 'react-dom'
import * as testUtils from 'react-dom/test-utils'
diff --git a/src/pure.js b/src/pure.js
index 8a062038..75098f78 100644
--- a/src/pure.js
+++ b/src/pure.js
@@ -1,4 +1,4 @@
-import React from 'react'
+import * as React from 'react'
import ReactDOM from 'react-dom'
import {
getQueriesForElement,
From 1fc17466722be4dcc3224b2997b9c1f3bda4f740 Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Fri, 30 Oct 2020 09:17:11 -0600
Subject: [PATCH 05/24] chore: adjust .travis to install latest npm (#812)
As recommended by @ljharb https://github.com/testing-library/react-testing-library/pull/809/files#r514441103
---
.travis.yml | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index fbe104b8..026c7f4b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -12,10 +12,9 @@ env:
- REACT_DIST=latest
- REACT_DIST=next
- REACT_DIST=experimental
+before_install:
+ - nvm install-latest-npm
install:
- # 7.0.6 fixed CI environments prompting user input.
- # Can be removed once node15 bumps the shipped npm version.
- - npm install --global npm@>=7.0.6
- npm install
# as requested by the React team :)
# https://reactjs.org/blog/2019/10/22/react-release-channels.html#using-the-next-channel-for-integration-testing
From 48d2e73d8e7c77d03c63ec0876faa4196fdcfde9 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Fri, 30 Oct 2020 09:18:54 -0600
Subject: [PATCH 06/24] docs: add ljharb as a contributor (#813)
* docs: update README.md
* docs: update .all-contributorsrc
* docs: update README.md
* docs: update .all-contributorsrc
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 10 ++++++++++
README.md | 2 +-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 0fd4f4ab..bf9b7cac 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -1203,6 +1203,16 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "ljharb",
+ "name": "Jordan Harband",
+ "avatar_url": "https://avatars1.githubusercontent.com/u/45469?v=4",
+ "profile": "https://github.com/ljharb",
+ "contributions": [
+ "review",
+ "ideas"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index a43cb5a6..32eba9dc 100644
--- a/README.md
+++ b/README.md
@@ -599,12 +599,12 @@ Thanks goes to these people ([emoji key][emojis]):
Karthick Raja π»
Abdelrahman Ashraf π»
Lidor Avitan π
+ Jordan Harband π π€
-
This project follows the [all-contributors][all-contributors] specification.
From e07e6416f25fd75df510c5d4211dc06f9f7398d7 Mon Sep 17 00:00:00 2001
From: Weyert de Boer
Date: Tue, 3 Nov 2020 14:25:18 +0000
Subject: [PATCH 07/24] fix: upgrade dependencies, typescript,
@testing-library/dom etc (#816)
Co-authored-by: Weyert de Boer
---
package.json | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/package.json b/package.json
index 9b314d91..e4b15e4a 100644
--- a/package.json
+++ b/package.json
@@ -43,20 +43,20 @@
"author": "Kent C. Dodds (https://kentcdodds.com)",
"license": "MIT",
"dependencies": {
- "@babel/runtime": "^7.11.2",
- "@testing-library/dom": "^7.26.0"
+ "@babel/runtime": "^7.12.1",
+ "@testing-library/dom": "^7.26.4"
},
"devDependencies": {
- "@testing-library/jest-dom": "^5.11.4",
+ "@testing-library/jest-dom": "^5.11.5",
"@types/react-dom": "^16.9.8",
- "dotenv-cli": "^3.2.0",
- "dtslint": "4.0.0",
- "kcd-scripts": "^6.3.0",
+ "dotenv-cli": "^4.0.0",
+ "dtslint": "4.0.4",
+ "kcd-scripts": "^6.6.0",
"npm-run-all": "^4.1.5",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"rimraf": "^3.0.2",
- "typescript": "^4.0.2"
+ "typescript": "^4.0.5"
},
"peerDependencies": {
"react": "*",
From 2712dc2da46bc8af456b4759d5e4b2c971c54092 Mon Sep 17 00:00:00 2001
From: Marco Moretti
Date: Tue, 10 Nov 2020 20:04:53 +0100
Subject: [PATCH 08/24] fix: import pretty-format from @testing-library/dom
(#821)
---
package.json | 2 +-
types/index.d.ts | 10 +++++++---
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/package.json b/package.json
index e4b15e4a..96c7df0f 100644
--- a/package.json
+++ b/package.json
@@ -44,7 +44,7 @@
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.12.1",
- "@testing-library/dom": "^7.26.4"
+ "@testing-library/dom": "^7.26.6"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.11.5",
diff --git a/types/index.d.ts b/types/index.d.ts
index 50702ecc..953f05d6 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -1,7 +1,11 @@
// TypeScript Version: 3.8
-import {OptionsReceived as PrettyFormatOptions} from 'pretty-format'
-import {queries, Queries, BoundFunction} from '@testing-library/dom'
+import {
+ queries,
+ Queries,
+ BoundFunction,
+ prettyFormat,
+} from '@testing-library/dom'
import {act as reactAct} from 'react-dom/test-utils'
export * from '@testing-library/dom'
@@ -15,7 +19,7 @@ export type RenderResult = {
| DocumentFragment
| Array,
maxLength?: number,
- options?: PrettyFormatOptions,
+ options?: prettyFormat.OptionsReceived,
) => void
rerender: (ui: React.ReactElement) => void
unmount: () => boolean
From 007b0b72d60fe018c950de1c07cb9889d7682f68 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Tue, 10 Nov 2020 12:09:13 -0700
Subject: [PATCH 09/24] docs: add marcosvega91 as a contributor (#822)
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 3 +++
2 files changed, 12 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index bf9b7cac..8c514263 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -1213,6 +1213,15 @@
"review",
"ideas"
]
+ },
+ {
+ "login": "marcosvega91",
+ "name": "Marco Moretti",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/5365582?v=4",
+ "profile": "https://github.com/marcosvega91",
+ "contributions": [
+ "code"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 32eba9dc..c7033e52 100644
--- a/README.md
+++ b/README.md
@@ -601,6 +601,9 @@ Thanks goes to these people ([emoji key][emojis]):
Lidor Avitan π
Jordan Harband π π€
+
+ Marco Moretti π»
+
From 3af1b4ba12dfc3a5c8f4968c1b92dba53823f9af Mon Sep 17 00:00:00 2001
From: Nick McCurdy
Date: Sat, 14 Nov 2020 11:19:21 -0500
Subject: [PATCH 10/24] chore: switch to github actions (#826)
Co-authored-by: Kent C. Dodds
---
.github/workflows/validate.yml | 88 ++++++++++++++++++++++++++++++++++
.travis.yml | 38 ---------------
README.md | 15 +++---
other/MAINTAINING.md | 8 ++--
package.json | 15 +++---
types/test.tsx | 26 ++++++----
6 files changed, 127 insertions(+), 63 deletions(-)
create mode 100644 .github/workflows/validate.yml
delete mode 100644 .travis.yml
diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml
new file mode 100644
index 00000000..dcb53ad2
--- /dev/null
+++ b/.github/workflows/validate.yml
@@ -0,0 +1,88 @@
+name: validate
+on:
+ push:
+ branches:
+ [
+ '+([0-9])?(.{+([0-9]),x}).x',
+ 'master',
+ 'next',
+ 'next-major',
+ 'beta',
+ 'alpha',
+ '!all-contributors/**',
+ ]
+ pull_request:
+ branches-ignore: ['all-contributors/**']
+jobs:
+ main:
+ continue-on-error: ${{ matrix.react != 'latest' }}
+ strategy:
+ matrix:
+ node: [10.13, 12, 14, 15]
+ react: [latest, next, experimental]
+ runs-on: ubuntu-latest
+ steps:
+ - name: β¬οΈ Checkout repo
+ uses: actions/checkout@v2
+
+ - name: β Setup node
+ uses: actions/setup-node@v1
+ with:
+ node-version: ${{ matrix.node }}
+
+ - name: π₯ Download deps
+ uses: bahmutov/npm-install@v1
+ with:
+ useLockFile: false
+
+ # as requested by the React team :)
+ # https://reactjs.org/blog/2019/10/22/react-release-channels.html#using-the-next-channel-for-integration-testing
+ - name: βοΈ Setup react
+ run: npm install react@${{matrix.react}} react-dom@${{matrix.react}}
+
+ - name: βΆοΈ Run validate script
+ run: npm run validate
+
+ - name: β¬οΈ Upload coverage report
+ uses: codecov/codecov-action@v1
+
+ release:
+ needs: main
+ runs-on: ubuntu-latest
+ if:
+ ${{ github.repository == 'testing-library/react-testing-library' &&
+ contains('refs/heads/master,refs/heads/beta,refs/heads/next,refs/heads/alpha',
+ github.ref) && github.event_name == 'push' }}
+ steps:
+ - name: β¬οΈ Checkout repo
+ uses: actions/checkout@v2
+
+ - name: β Setup node
+ uses: actions/setup-node@v1
+ with:
+ node-version: 14
+
+ - name: π₯ Download deps
+ uses: bahmutov/npm-install@v1
+ with:
+ useLockFile: false
+
+ - name: π Run build script
+ run: npm run build
+
+ - name: π Release
+ uses: cycjimmy/semantic-release-action@v2
+ with:
+ semantic_version: 17
+ branches: |
+ [
+ '+([0-9])?(.{+([0-9]),x}).x',
+ 'master',
+ 'next',
+ 'next-major',
+ {name: 'beta', prerelease: true},
+ {name: 'alpha', prerelease: true}
+ ]
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 026c7f4b..00000000
--- a/.travis.yml
+++ /dev/null
@@ -1,38 +0,0 @@
-language: node_js
-cache: npm
-notifications:
- email: false
-node_js:
- # technically we support 10.0.0, but some of our tooling doesn't
- - 10.14.2
- - 12
- - 14
- - 15
-env:
- - REACT_DIST=latest
- - REACT_DIST=next
- - REACT_DIST=experimental
-before_install:
- - nvm install-latest-npm
-install:
- - npm install
- # as requested by the React team :)
- # https://reactjs.org/blog/2019/10/22/react-release-channels.html#using-the-next-channel-for-integration-testing
- - npm install react@$REACT_DIST react-dom@$REACT_DIST
-script:
- - npm run validate
- - npx codecov@3
-branches:
- only:
- - master
- - beta
-
-jobs:
- allow_failures:
- - REACT_DIST=next
- - REACT_DIST=experimental
- include:
- - stage: release
- node_js: 14
- script: kcd-scripts travis-release
- if: fork = false
diff --git a/README.md b/README.md
index c7033e52..73e421bb 100644
--- a/README.md
+++ b/README.md
@@ -26,11 +26,12 @@ practices.
[![Build Status][build-badge]][build]
[![Code Coverage][coverage-badge]][coverage]
-[![version][version-badge]][package] [![downloads][downloads-badge]][npmtrends]
+[![version][version-badge]][package]
+[![downloads][downloads-badge]][npmtrends]
[![MIT License][license-badge]][license]
-
-[](#contributors)
-[![PRs Welcome][prs-badge]][prs] [![Code of Conduct][coc-badge]][coc]
+[![All Contributors][all-contributors-badge]](#contributors)
+[![PRs Welcome][prs-badge]][prs]
+[![Code of Conduct][coc-badge]][coc]
[![Discord][discord-badge]][discord]
[![Watch on GitHub][github-watch-badge]][github-watch]
@@ -608,6 +609,7 @@ Thanks goes to these people ([emoji key][emojis]):
+
This project follows the [all-contributors][all-contributors] specification.
@@ -622,8 +624,8 @@ Contributions of any kind welcome!
[npm]: https://www.npmjs.com/
[yarn]: https://classic.yarnpkg.com
[node]: https://nodejs.org
-[build-badge]: https://img.shields.io/travis/testing-library/react-testing-library.svg?style=flat-square
-[build]: https://travis-ci.org/testing-library/react-testing-library
+[build-badge]: https://img.shields.io/github/workflow/status/testing-library/react-testing-library/validate?logo=github&style=flat-square
+[build]: https://github.com/testing-library/react-testing-library/actions?query=workflow%3Avalidate
[coverage-badge]: https://img.shields.io/codecov/c/github/testing-library/react-testing-library.svg?style=flat-square
[coverage]: https://codecov.io/github/testing-library/react-testing-library
[version-badge]: https://img.shields.io/npm/v/@testing-library/react.svg?style=flat-square
@@ -644,6 +646,7 @@ Contributions of any kind welcome!
[twitter-badge]: https://img.shields.io/twitter/url/https/github.com/testing-library/react-testing-library.svg?style=social
[emojis]: https://github.com/all-contributors/all-contributors#emoji-key
[all-contributors]: https://github.com/all-contributors/all-contributors
+[all-contributors-badge]: https://img.shields.io/github/all-contributors/testing-library/react-testing-library?color=orange&style=flat-square
[guiding-principle]: https://twitter.com/kentcdodds/status/977018512689455106
[bugs]: https://github.com/testing-library/react-testing-library/issues?q=is%3Aissue+is%3Aopen+label%3Abug+sort%3Acreated-desc
[requests]: https://github.com/testing-library/react-testing-library/issues?q=is%3Aissue+sort%3Areactions-%2B1-desc+label%3Aenhancement+is%3Aopen
diff --git a/other/MAINTAINING.md b/other/MAINTAINING.md
index 703126da..cade1c2a 100644
--- a/other/MAINTAINING.md
+++ b/other/MAINTAINING.md
@@ -32,9 +32,9 @@ any more of you than that.
As a maintainer, you're fine to make your branches on the main repo or on your
own fork. Either way is fine.
-When we receive a pull request, a travis build is kicked off automatically (see
-the `.travis.yml` for what runs in the travis build). We avoid merging anything
-that breaks the travis build.
+When we receive a pull request, a github action is kicked off automatically (see
+the `.github/workflows/validate.yml` for what runs in the action). We avoid
+merging anything that breaks the validate action.
Please review PRs and focus on the code rather than the individual. You never
know when this is someone's first ever PR and we want their experience to be as
@@ -49,7 +49,7 @@ to release. See the next section on Releases for more about that.
## Release
Our releases are automatic. They happen whenever code lands into `master`. A
-travis build gets kicked off and if it's successful, a tool called
+github action gets kicked off and if it's successful, a tool called
[`semantic-release`](https://github.com/semantic-release/semantic-release) is
used to automatically publish a new release to npm as well as a changelog to
GitHub. It is only able to determine the version and whether a release is
diff --git a/package.json b/package.json
index 96c7df0f..086e82bc 100644
--- a/package.json
+++ b/package.json
@@ -43,18 +43,19 @@
"author": "Kent C. Dodds (https://kentcdodds.com)",
"license": "MIT",
"dependencies": {
- "@babel/runtime": "^7.12.1",
+ "@babel/runtime": "^7.12.5",
"@testing-library/dom": "^7.26.6"
},
"devDependencies": {
- "@testing-library/jest-dom": "^5.11.5",
- "@types/react-dom": "^16.9.8",
+ "@testing-library/jest-dom": "^5.11.6",
+ "@types/estree": "0.0.45",
+ "@types/react-dom": "^16.9.9",
"dotenv-cli": "^4.0.0",
- "dtslint": "4.0.4",
- "kcd-scripts": "^6.6.0",
+ "dtslint": "4.0.5",
+ "kcd-scripts": "^7.0.3",
"npm-run-all": "^4.1.5",
- "react": "^16.13.1",
- "react-dom": "^16.13.1",
+ "react": "^17.0.1",
+ "react-dom": "^17.0.1",
"rimraf": "^3.0.2",
"typescript": "^4.0.5"
},
diff --git a/types/test.tsx b/types/test.tsx
index c273feb0..3971037d 100644
--- a/types/test.tsx
+++ b/types/test.tsx
@@ -2,7 +2,7 @@ import * as React from 'react'
import {render, fireEvent, screen, waitFor} from '@testing-library/react'
import * as pure from '@testing-library/react/pure'
-async function testRender() {
+export async function testRender() {
const page = render(
)
// single queries
@@ -17,9 +17,10 @@ async function testRender() {
// helpers
const {container, rerender, debug} = page
+ return {container, rerender, debug}
}
-async function testPureRender() {
+export async function testPureRender() {
const page = pure.render(
)
// single queries
@@ -34,20 +35,21 @@ async function testPureRender() {
// helpers
const {container, rerender, debug} = page
+ return {container, rerender, debug}
}
-async function testRenderOptions() {
+export function testRenderOptions() {
const container = document.createElement('div')
const options = {container}
render(
, options)
}
-async function testFireEvent() {
+export function testFireEvent() {
const {container} = render( )
fireEvent.click(container)
}
-async function testDebug() {
+export function testDebug() {
const {debug, getAllByTestId} = render(
<>
Hello World
@@ -57,14 +59,22 @@ async function testDebug() {
debug(getAllByTestId('testid'))
}
-async function testScreen() {
+export async function testScreen() {
render( )
- screen.findByRole('button')
+ await screen.findByRole('button')
}
-async function testWaitFor() {
+export async function testWaitFor() {
const {container} = render( )
fireEvent.click(container)
await waitFor(() => {})
}
+
+/*
+eslint
+ testing-library/prefer-explicit-assert: "off",
+ testing-library/no-wait-for-empty-callback: "off",
+ testing-library/no-debug: "off",
+ testing-library/prefer-screen-queries: "off"
+*/
From 96b9aebe96ab93d62ba7b2aba2c03bf844ea10ac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?=
Date: Mon, 16 Nov 2020 15:02:29 +0100
Subject: [PATCH 11/24] chore: Update validate.yml (#827)
---
.github/workflows/validate.yml | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml
index dcb53ad2..02277648 100644
--- a/.github/workflows/validate.yml
+++ b/.github/workflows/validate.yml
@@ -2,20 +2,19 @@ name: validate
on:
push:
branches:
- [
- '+([0-9])?(.{+([0-9]),x}).x',
- 'master',
- 'next',
- 'next-major',
- 'beta',
- 'alpha',
- '!all-contributors/**',
- ]
- pull_request:
- branches-ignore: ['all-contributors/**']
+ - '+([0-9])?(.{+([0-9]),x}).x'
+ - 'master'
+ - 'next'
+ - 'next-major'
+ - 'beta'
+ - 'alpha'
+ - '!all-contributors/**'
+ pull_request: {}
jobs:
main:
continue-on-error: ${{ matrix.react != 'latest' }}
+ # ignore all-contributors PRs
+ if: ${{ !contains(github.head_ref, 'all-contributors') }}
strategy:
matrix:
node: [10.13, 12, 14, 15]
@@ -38,7 +37,7 @@ jobs:
# as requested by the React team :)
# https://reactjs.org/blog/2019/10/22/react-release-channels.html#using-the-next-channel-for-integration-testing
- name: βοΈ Setup react
- run: npm install react@${{matrix.react}} react-dom@${{matrix.react}}
+ run: npm install react@${{ matrix.react }} react-dom@${{ matrix.react }}
- name: βΆοΈ Run validate script
run: npm run validate
From 236ea4962d06e713885b0295dda1c415c6af811b Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Tue, 17 Nov 2020 16:55:01 -0700
Subject: [PATCH 12/24] chore: remove one temporary fix with a better permenant
one
---
package.json | 1 -
types/tsconfig.json | 1 +
2 files changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 086e82bc..8ba28958 100644
--- a/package.json
+++ b/package.json
@@ -48,7 +48,6 @@
},
"devDependencies": {
"@testing-library/jest-dom": "^5.11.6",
- "@types/estree": "0.0.45",
"@types/react-dom": "^16.9.9",
"dotenv-cli": "^4.0.0",
"dtslint": "4.0.5",
diff --git a/types/tsconfig.json b/types/tsconfig.json
index a6ba6c3d..aeacacb0 100644
--- a/types/tsconfig.json
+++ b/types/tsconfig.json
@@ -11,6 +11,7 @@
"strictFunctionTypes": true,
"noEmit": true,
"baseUrl": ".",
+ "skipLibCheck": true,
"paths": {
"@testing-library/react": ["."],
"@testing-library/react/pure": ["."]
From 456424ff33ea8d5156e5d86c64a756c6f852d96d Mon Sep 17 00:00:00 2001
From: Ben Monro
Date: Wed, 18 Nov 2020 08:42:12 -0800
Subject: [PATCH 13/24] feat: bump dom testing library (#831)
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 8ba28958..4792c6cc 100644
--- a/package.json
+++ b/package.json
@@ -44,7 +44,7 @@
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.12.5",
- "@testing-library/dom": "^7.26.6"
+ "@testing-library/dom": "^7.27.1"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.11.6",
From 1dc33b23bec6d033d65674ac6e1c2dd7e9a71202 Mon Sep 17 00:00:00 2001
From: Joseph R Miles
Date: Thu, 19 Nov 2020 02:41:09 -0800
Subject: [PATCH 14/24] fix(types): Allow all HTML and SVG elements in render.
(#833)
Co-authored-by: Sebastian Silbermann
---
types/index.d.ts | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/types/index.d.ts b/types/index.d.ts
index 953f05d6..3dcaf10c 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -11,13 +11,13 @@ import {act as reactAct} from 'react-dom/test-utils'
export * from '@testing-library/dom'
export type RenderResult = {
- container: HTMLElement
- baseElement: HTMLElement
+ container: Element
+ baseElement: Element
debug: (
baseElement?:
- | HTMLElement
+ | Element
| DocumentFragment
- | Array,
+ | Array,
maxLength?: number,
options?: prettyFormat.OptionsReceived,
) => void
@@ -27,8 +27,8 @@ export type RenderResult = {
} & {[P in keyof Q]: BoundFunction}
export interface RenderOptions {
- container?: HTMLElement
- baseElement?: HTMLElement
+ container?: Element
+ baseElement?: Element
hydrate?: boolean
queries?: Q
wrapper?: React.ComponentType
From 276673ff001858fc5844df35114bf32e48bcdc1a Mon Sep 17 00:00:00 2001
From: Nick McCurdy
Date: Thu, 19 Nov 2020 09:45:06 -0500
Subject: [PATCH 15/24] chore(types): add test for rendering SVG elements
(#834)
---
types/test.tsx | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/types/test.tsx b/types/test.tsx
index 3971037d..07c4dbb7 100644
--- a/types/test.tsx
+++ b/types/test.tsx
@@ -44,6 +44,15 @@ export function testRenderOptions() {
render(
, options)
}
+export function testSVGRenderOptions() {
+ const container = document.createElementNS(
+ 'http://www.w3.org/2000/svg',
+ 'svg',
+ )
+ const options = {container}
+ render( , options)
+}
+
export function testFireEvent() {
const {container} = render( )
fireEvent.click(container)
From 7fcb0f2e930a34bc1a0fa3dc964cd05a74fdfefd Mon Sep 17 00:00:00 2001
From: Ben Monro
Date: Fri, 20 Nov 2020 15:31:49 -0800
Subject: [PATCH 16/24] fix(dependencies): bump dom testing library (#836)
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 4792c6cc..79726397 100644
--- a/package.json
+++ b/package.json
@@ -44,7 +44,7 @@
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.12.5",
- "@testing-library/dom": "^7.27.1"
+ "@testing-library/dom": "^7.28.1"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.11.6",
From 03bea9fd76349f458b6aff7b472acefe1879375f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?=
Date: Wed, 2 Dec 2020 20:08:37 +0100
Subject: [PATCH 17/24] chore: Add 'Cancel Previous Runs' step (#840)
Co-authored-by: Kent C. Dodds
---
.github/workflows/validate.yml | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml
index 02277648..e99fa965 100644
--- a/.github/workflows/validate.yml
+++ b/.github/workflows/validate.yml
@@ -21,6 +21,11 @@ jobs:
react: [latest, next, experimental]
runs-on: ubuntu-latest
steps:
+ - name: π Cancel Previous Runs
+ uses: styfle/cancel-workflow-action@0.6.0
+ with:
+ access_token: ${{ secrets.GITHUB_TOKEN }}
+
- name: β¬οΈ Checkout repo
uses: actions/checkout@v2
@@ -53,6 +58,11 @@ jobs:
contains('refs/heads/master,refs/heads/beta,refs/heads/next,refs/heads/alpha',
github.ref) && github.event_name == 'push' }}
steps:
+ - name: π Cancel Previous Runs
+ uses: styfle/cancel-workflow-action@0.6.0
+ with:
+ access_token: ${{ secrets.GITHUB_TOKEN }}
+
- name: β¬οΈ Checkout repo
uses: actions/checkout@v2
From 64a8b9c2f30922d362028d9c6a31543c1874d1c7 Mon Sep 17 00:00:00 2001
From: "Kent C. Dodds"
Date: Fri, 4 Dec 2020 11:34:48 -0700
Subject: [PATCH 18/24] chore: update all deps (#842)
---
package.json | 9 ++++-----
src/__tests__/rerender.js | 4 ++--
types/test.tsx | 4 ++--
types/tsconfig.json | 20 ++------------------
types/tslint.json | 9 ---------
5 files changed, 10 insertions(+), 36 deletions(-)
delete mode 100644 types/tslint.json
diff --git a/package.json b/package.json
index 79726397..d1d6aa36 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,7 @@
"setup": "npm install && npm run validate -s",
"test": "kcd-scripts test",
"test:update": "npm test -- --updateSnapshot --coverage",
- "typecheck": "dtslint ./types/",
+ "typecheck": "kcd-scripts typecheck --build types",
"validate": "kcd-scripts validate"
},
"files": [
@@ -48,15 +48,14 @@
},
"devDependencies": {
"@testing-library/jest-dom": "^5.11.6",
- "@types/react-dom": "^16.9.9",
+ "@types/react-dom": "^17.0.0",
"dotenv-cli": "^4.0.0",
- "dtslint": "4.0.5",
- "kcd-scripts": "^7.0.3",
+ "kcd-scripts": "^7.5.1",
"npm-run-all": "^4.1.5",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"rimraf": "^3.0.2",
- "typescript": "^4.0.5"
+ "typescript": "^4.1.2"
},
"peerDependencies": {
"react": "*",
diff --git a/src/__tests__/rerender.js b/src/__tests__/rerender.js
index f8ea377e..be3c259c 100644
--- a/src/__tests__/rerender.js
+++ b/src/__tests__/rerender.js
@@ -23,9 +23,9 @@ test('hydrate will not update props until next render', () => {
hydrate: true,
})
- expect(initialInputElement.value).toBe(firstValue)
+ expect(initialInputElement).toHaveValue(firstValue)
const secondValue = 'goodbye'
rerender( null} />)
- expect(initialInputElement.value).toBe(secondValue)
+ expect(initialInputElement).toHaveValue(secondValue)
})
diff --git a/types/test.tsx b/types/test.tsx
index 07c4dbb7..1366caac 100644
--- a/types/test.tsx
+++ b/types/test.tsx
@@ -1,6 +1,6 @@
import * as React from 'react'
-import {render, fireEvent, screen, waitFor} from '@testing-library/react'
-import * as pure from '@testing-library/react/pure'
+import {render, fireEvent, screen, waitFor} from '.'
+import * as pure from './pure'
export async function testRender() {
const page = render(
)
diff --git a/types/tsconfig.json b/types/tsconfig.json
index aeacacb0..a7829065 100644
--- a/types/tsconfig.json
+++ b/types/tsconfig.json
@@ -1,20 +1,4 @@
-// this additional tsconfig is required by dtslint
-// see: https://github.com/Microsoft/dtslint#typestsconfigjson
{
- "compilerOptions": {
- "module": "commonjs",
- "lib": ["es6", "dom"],
- "jsx": "react",
- "noImplicitAny": true,
- "noImplicitThis": true,
- "strictNullChecks": true,
- "strictFunctionTypes": true,
- "noEmit": true,
- "baseUrl": ".",
- "skipLibCheck": true,
- "paths": {
- "@testing-library/react": ["."],
- "@testing-library/react/pure": ["."]
- }
- }
+ "extends": "../node_modules/kcd-scripts/shared-tsconfig.json",
+ "include": ["."]
}
diff --git a/types/tslint.json b/types/tslint.json
deleted file mode 100644
index cb0fce9f..00000000
--- a/types/tslint.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "extends": ["dtslint/dtslint.json"],
- "rules": {
- "no-useless-files": false,
- "no-relative-import-in-test": false,
- "semicolon": false,
- "whitespace": false
- }
-}
From 1389f094748991b3a900e2fcc9f4bf21df212da9 Mon Sep 17 00:00:00 2001
From: sanchit121 <30828115+sanchit121@users.noreply.github.com>
Date: Thu, 7 Jan 2021 23:29:45 +0530
Subject: [PATCH 19/24] fix: Return type of unmount is `void` (#857)
Co-authored-by: Sanchit Agarwal
---
types/index.d.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/types/index.d.ts b/types/index.d.ts
index 3dcaf10c..8e0d1c02 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -22,7 +22,7 @@ export type RenderResult = {
options?: prettyFormat.OptionsReceived,
) => void
rerender: (ui: React.ReactElement) => void
- unmount: () => boolean
+ unmount: () => void
asFragment: () => DocumentFragment
} & {[P in keyof Q]: BoundFunction}
From deafd51bc20209612674dbdaba920750c1d6352e Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Thu, 7 Jan 2021 19:00:46 +0100
Subject: [PATCH 20/24] docs: add sanchit121 as a contributor (#858)
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 10 ++
README.md | 257 ++++++++++++++++++++++----------------------
2 files changed, 139 insertions(+), 128 deletions(-)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 8c514263..ed301861 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -1222,6 +1222,16 @@
"contributions": [
"code"
]
+ },
+ {
+ "login": "sanchit121",
+ "name": "sanchit121",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/30828115?v=4",
+ "profile": "https://github.com/sanchit121",
+ "contributions": [
+ "bug",
+ "code"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 73e421bb..06a1fbdd 100644
--- a/README.md
+++ b/README.md
@@ -441,173 +441,174 @@ Thanks goes to these people ([emoji key][emojis]):
-
+
From 2a3be2c9064134bc3dcf7b88e438011a02d2baa3 Mon Sep 17 00:00:00 2001
From: Nick McCurdy
Date: Tue, 19 Jan 2021 19:51:19 -0500
Subject: [PATCH 21/24] docs: use vanity URL for Discord
---
.github/ISSUE_TEMPLATE.md | 3 ++-
.github/ISSUE_TEMPLATE/Question.md | 2 +-
README.md | 2 +-
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md
index 01d98992..496c8563 100644
--- a/.github/ISSUE_TEMPLATE.md
+++ b/.github/ISSUE_TEMPLATE.md
@@ -23,7 +23,7 @@ Thanks for your interest in the project. We appreciate bugs filed and PRs submit
instead of filing an issue on GitHub. You can follow the instructions in this
codesandbox to make a reproduction of your issue: https://kcd.im/rtl-help
* Discord
- https://discord.gg/c6JN9fM
+ https://discord.gg/testing-library
* Stack Overflow
https://stackoverflow.com/questions/tagged/react-testing-library
@@ -61,6 +61,7 @@ for the supported version.
Relevant code or config
```javascript
+
```
What you did:
diff --git a/.github/ISSUE_TEMPLATE/Question.md b/.github/ISSUE_TEMPLATE/Question.md
index d9a372d9..e625486b 100644
--- a/.github/ISSUE_TEMPLATE/Question.md
+++ b/.github/ISSUE_TEMPLATE/Question.md
@@ -16,7 +16,7 @@ For questions related to using the library, please visit a support community
instead of filing an issue on GitHub. You can follow the instructions in this
codesandbox to make a reproduction of your issue: https://kcd.im/rtl-help
-- Discord https://discord.gg/c6JN9fM
+- Discord https://discord.gg/testing-library
- Stack Overflow
https://stackoverflow.com/questions/tagged/react-testing-library
- Documentation: https://github.com/testing-library/testing-library-docs
diff --git a/README.md b/README.md
index 06a1fbdd..9d9efb5d 100644
--- a/README.md
+++ b/README.md
@@ -653,7 +653,7 @@ Contributions of any kind welcome!
[requests]: https://github.com/testing-library/react-testing-library/issues?q=is%3Aissue+sort%3Areactions-%2B1-desc+label%3Aenhancement+is%3Aopen
[good-first-issue]: https://github.com/testing-library/react-testing-library/issues?utf8=β&q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc+label%3A"good+first+issue"+
[discord-badge]: https://img.shields.io/discord/723559267868737556.svg?color=7389D8&labelColor=6A7EC2&logo=discord&logoColor=ffffff&style=flat-square
-[discord]: https://discord.gg/c6JN9fM
+[discord]: https://discord.gg/testing-library
[stackoverflow]: https://stackoverflow.com/questions/tagged/react-testing-library
[react-hooks-testing-library]: https://github.com/testing-library/react-hooks-testing-library
From 81c2de90c621df4f0702db02adf0c1f31bc08cd6 Mon Sep 17 00:00:00 2001
From: Sebastian Silbermann
Date: Tue, 2 Feb 2021 10:30:49 +0100
Subject: [PATCH 22/24] fix(render): Default to HTMLElement in returned
container (#868)
---
types/index.d.ts | 26 ++++++++++++++++++--------
types/test.tsx | 36 ++++++++++++++++++++++++++++++++----
2 files changed, 50 insertions(+), 12 deletions(-)
diff --git a/types/index.d.ts b/types/index.d.ts
index 8e0d1c02..4d599256 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -6,12 +6,16 @@ import {
BoundFunction,
prettyFormat,
} from '@testing-library/dom'
+import {Renderer} from 'react-dom'
import {act as reactAct} from 'react-dom/test-utils'
export * from '@testing-library/dom'
-export type RenderResult = {
- container: Element
+export type RenderResult<
+ Q extends Queries = typeof queries,
+ Container extends Element | DocumentFragment = HTMLElement
+> = {
+ container: Container
baseElement: Element
debug: (
baseElement?:
@@ -26,8 +30,11 @@ export type RenderResult = {
asFragment: () => DocumentFragment
} & {[P in keyof Q]: BoundFunction}
-export interface RenderOptions {
- container?: Element
+export interface RenderOptions<
+ Q extends Queries = typeof queries,
+ Container extends Element | DocumentFragment = HTMLElement
+> {
+ container?: Container
baseElement?: Element
hydrate?: boolean
queries?: Q
@@ -39,14 +46,17 @@ type Omit = Pick>
/**
* Render into a container which is appended to document.body. It should be used with cleanup.
*/
+export function render<
+ Q extends Queries,
+ Container extends Element | DocumentFragment = HTMLElement
+>(
+ ui: React.ReactElement,
+ options: RenderOptions,
+): RenderResult
export function render(
ui: React.ReactElement,
options?: Omit,
): RenderResult
-export function render(
- ui: React.ReactElement,
- options: RenderOptions,
-): RenderResult
/**
* Unmounts React trees that were mounted with render.
diff --git a/types/test.tsx b/types/test.tsx
index 1366caac..7cc0e015 100644
--- a/types/test.tsx
+++ b/types/test.tsx
@@ -3,7 +3,7 @@ import {render, fireEvent, screen, waitFor} from '.'
import * as pure from './pure'
export async function testRender() {
- const page = render(
)
+ const page = render( )
// single queries
page.getByText('foo')
@@ -17,11 +17,12 @@ export async function testRender() {
// helpers
const {container, rerender, debug} = page
+ expectType(container)
return {container, rerender, debug}
}
export async function testPureRender() {
- const page = pure.render(
)
+ const page = pure.render( )
// single queries
page.getByText('foo')
@@ -35,13 +36,15 @@ export async function testPureRender() {
// helpers
const {container, rerender, debug} = page
+ expectType(container)
return {container, rerender, debug}
}
export function testRenderOptions() {
const container = document.createElement('div')
const options = {container}
- render(
, options)
+ const {container: returnedContainer} = render( , options)
+ expectType(returnedContainer)
}
export function testSVGRenderOptions() {
@@ -50,7 +53,8 @@ export function testSVGRenderOptions() {
'svg',
)
const options = {container}
- render( , options)
+ const {container: returnedContainer} = render( , options)
+ expectType(returnedContainer)
}
export function testFireEvent() {
@@ -87,3 +91,27 @@ eslint
testing-library/no-debug: "off",
testing-library/prefer-screen-queries: "off"
*/
+
+// https://stackoverflow.com/questions/53807517/how-to-test-if-two-types-are-exactly-the-same
+type IfEquals = (() => G extends T
+ ? 1
+ : 2) extends () => G extends U ? 1 : 2
+ ? Yes
+ : No
+
+/**
+ * Issues a type error if `Expected` is not identical to `Actual`.
+ *
+ * `Expected` should be declared when invoking `expectType`.
+ * `Actual` should almost always we be a `typeof value` statement.
+ *
+ * Source: https://github.com/mui-org/material-ui/blob/6221876a4b468a3330ffaafa8472de7613933b87/packages/material-ui-types/index.d.ts#L73-L84
+ *
+ * @example `expectType(value)`
+ * TypeScript issues a type error since `value is not assignable to never`.
+ * This means `typeof value` is not identical to `number | string`
+ * @param actual
+ */
+declare function expectType(
+ actual: IfEquals,
+): void
From 5576e6f71445fd08cb10a58b571976eb410699ec Mon Sep 17 00:00:00 2001
From: Solufa
Date: Wed, 3 Feb 2021 01:33:01 +0900
Subject: [PATCH 23/24] fix(render): add default type for Queries parameter
(#871)
---
types/index.d.ts | 2 +-
types/test.tsx | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/types/index.d.ts b/types/index.d.ts
index 4d599256..6d0c67ee 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -47,7 +47,7 @@ type Omit = Pick>
* Render into a container which is appended to document.body. It should be used with cleanup.
*/
export function render<
- Q extends Queries,
+ Q extends Queries = typeof queries,
Container extends Element | DocumentFragment = HTMLElement
>(
ui: React.ReactElement,
diff --git a/types/test.tsx b/types/test.tsx
index 7cc0e015..01105c06 100644
--- a/types/test.tsx
+++ b/types/test.tsx
@@ -84,6 +84,22 @@ export async function testWaitFor() {
await waitFor(() => {})
}
+export function testQueries() {
+ const {getByLabelText} = render(
+ Username ,
+ )
+ expectType>(
+ getByLabelText('Username'),
+ )
+
+ const container = document.createElement('div')
+ const options = {container}
+ const {getByText} = render(Hello World
, options)
+ expectType>(
+ getByText('Hello World'),
+ )
+}
+
/*
eslint
testing-library/prefer-explicit-assert: "off",
From cbe020ada151a92aa1be46a695354a33045aafac Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Tue, 2 Feb 2021 17:36:20 +0100
Subject: [PATCH 24/24] docs: add solufa as a contributor (#872)
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 10 ++++++++++
README.md | 1 +
2 files changed, 11 insertions(+)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index ed301861..3ef0ecdf 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -1232,6 +1232,16 @@
"bug",
"code"
]
+ },
+ {
+ "login": "solufa",
+ "name": "Solufa",
+ "avatar_url": "https://avatars.githubusercontent.com/u/9402912?v=4",
+ "profile": "https://github.com/solufa",
+ "contributions": [
+ "bug",
+ "code"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 9d9efb5d..c46eac6d 100644
--- a/README.md
+++ b/README.md
@@ -605,6 +605,7 @@ Thanks goes to these people ([emoji key][emojis]):
Marco Moretti π»
sanchit121 π π»
+ Solufa π π»