Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: testing-library/react-testing-library
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 35522b1af7b72f771157d591387e84090fcf78f4
Choose a base ref
...
head repository: testing-library/react-testing-library
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f26b8df20369ab4bb41a462d6123819d526e53b9
Choose a head ref
  • 9 commits
  • 18 files changed
  • 4 contributors

Commits on Mar 4, 2020

  1. docs: add MichaelDeBoey as a contributor (#599)

    * docs: update README.md
    
    * docs: update .all-contributorsrc
    Kent C. Dodds authored Mar 4, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    04e64bb View commit details

Commits on Mar 7, 2020

  1. docs: add stevenfitzpatrick as a contributor (#604)

    * docs: update README.md
    
    * docs: update .all-contributorsrc
    
    Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
    allcontributors[bot] authored Mar 7, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2613d66 View commit details

Commits on Mar 11, 2020

  1. chore: fix typo (#608)

    remove extra `been`.
    Juan Je García authored Mar 11, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3d48019 View commit details
  2. docs: add juangl as a contributor (#609)

    * docs: update README.md
    
    * docs: update .all-contributorsrc
    
    Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
    allcontributors[bot] authored Mar 11, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0890ccc View commit details

Commits on Mar 12, 2020

  1. feat: update @testing-library/dom

    BREAKING CHANGE: The latest version of DOM Testing Library has several breaking changes you will want to review the changelog of DOM Testing Library to ensure you are uneffected.
    kentcdodds committed Mar 12, 2020
    Copy the full SHA
    435098c View commit details
  2. fix(node): drop Node 8 support (#576)

    Closes #575
    
    BREAKING CHANGE: This release drops support for Node 8. Upgrade to Node 10 or greater.
    kentcdodds committed Mar 12, 2020
    Copy the full SHA
    fccc2cf View commit details
  3. feat: Flush microtasks in cleanup (#519)

    Kent C. Dodds authored and kentcdodds committed Mar 12, 2020
    Copy the full SHA
    9fc8581 View commit details
  4. fix: remove deprecated cleanup-after-each (#598)

    BREAKING CHANGE: This removes `@testing-library/react/cleanup-after-each` which is deprecated and hasn't done anything for many versions.
    kentcdodds committed Mar 12, 2020
    Copy the full SHA
    7942f68 View commit details
  5. chore: cleanup repo (#600)

    Kent C. Dodds authored and kentcdodds committed Mar 12, 2020
    Copy the full SHA
    f26b8df View commit details
Showing with 70 additions and 73 deletions.
  1. +20 −1 .all-contributorsrc
  2. +1 −2 .gitattributes
  3. +0 −6 .gitignore
  4. +1 −2 .prettierignore
  5. +0 −11 .prettierrc
  6. +1 −0 .prettierrc.js
  7. +1 −1 .travis.yml
  8. +3 −1 README.md
  9. +0 −4 cleanup-after-each.js
  10. +10 −11 package.json
  11. +3 −3 src/__tests__/act.js
  12. +4 −4 src/__tests__/cleanup.js
  13. +3 −3 src/__tests__/debug.js
  14. +5 −7 src/__tests__/end-to-end.js
  15. +6 −6 src/__tests__/render.js
  16. +6 −5 src/__tests__/stopwatch.js
  17. +1 −3 src/index.js
  18. +5 −3 src/pure.js
21 changes: 20 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -912,7 +912,8 @@
"avatar_url": "https://avatars3.githubusercontent.com/u/6643991?v=4",
"profile": "https://michaeldeboey.be",
"contributions": [
"review"
"review",
"code"
]
},
{
@@ -1035,6 +1036,24 @@
"contributions": [
"ideas"
]
},
{
"login": "stevenfitzpatrick",
"name": "Steven Fitzpatrick",
"avatar_url": "https://avatars0.githubusercontent.com/u/23268855?v=4",
"profile": "https://github.com/stevenfitzpatrick",
"contributions": [
"bug"
]
},
{
"login": "juangl",
"name": "Juan Je García",
"avatar_url": "https://avatars0.githubusercontent.com/u/1887029?v=4",
"profile": "https://github.com/juangl",
"contributions": [
"doc"
]
}
],
"contributorsPerLine": 7,
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
node_modules
coverage
dist
.opt-in
.opt-out
.DS_Store
.eslintcache

yarn-error.log

# these cause more harm than good
# when working with contributors
package-lock.json
yarn.lock

3 changes: 1 addition & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package.json
node_modules
dist
coverage
dist
11 changes: 0 additions & 11 deletions .prettierrc

This file was deleted.

1 change: 1 addition & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('kcd-scripts/prettier')
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ cache: npm
notifications:
email: false
node_js:
- 10.14
- 10.18
- 12
- node
install:
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -508,7 +508,7 @@ Thanks goes to these people ([emoji key][emojis]):
<tr>
<td align="center"><a href="https://afontcu.dev"><img src="https://avatars0.githubusercontent.com/u/9197791?v=4" width="100px;" alt=""/><br /><sub><b>Adrià Fontcuberta</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/pulls?q=is%3Apr+reviewed-by%3Aafontcu" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/testing-library/react-testing-library/commits?author=afontcu" title="Documentation">📖</a></td>
<td align="center"><a href="https://blog.johnnyreilly.com/"><img src="https://avatars0.githubusercontent.com/u/1010525?v=4" width="100px;" alt=""/><br /><sub><b>John Reilly</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/pulls?q=is%3Apr+reviewed-by%3Ajohnnyreilly" title="Reviewed Pull Requests">👀</a></td>
<td align="center"><a href="https://michaeldeboey.be"><img src="https://avatars3.githubusercontent.com/u/6643991?v=4" width="100px;" alt=""/><br /><sub><b>Michaël De Boey</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/pulls?q=is%3Apr+reviewed-by%3AMichaelDeBoey" title="Reviewed Pull Requests">👀</a></td>
<td align="center"><a href="https://michaeldeboey.be"><img src="https://avatars3.githubusercontent.com/u/6643991?v=4" width="100px;" alt=""/><br /><sub><b>Michaël De Boey</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/pulls?q=is%3Apr+reviewed-by%3AMichaelDeBoey" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/testing-library/react-testing-library/commits?author=MichaelDeBoey" title="Code">💻</a></td>
<td align="center"><a href="https://cimbul.com"><img src="https://avatars2.githubusercontent.com/u/927923?v=4" width="100px;" alt=""/><br /><sub><b>Tim Yates</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/pulls?q=is%3Apr+reviewed-by%3Acimbul" title="Reviewed Pull Requests">👀</a></td>
<td align="center"><a href="https://github.com/eventualbuddha"><img src="https://avatars3.githubusercontent.com/u/1938?v=4" width="100px;" alt=""/><br /><sub><b>Brian Donovan</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/commits?author=eventualbuddha" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/JaysQubeXon"><img src="https://avatars1.githubusercontent.com/u/18309230?v=4" width="100px;" alt=""/><br /><sub><b>Noam Gabriel Jacobson</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/commits?author=JaysQubeXon" title="Documentation">📖</a></td>
@@ -526,6 +526,8 @@ Thanks goes to these people ([emoji key][emojis]):
<tr>
<td align="center"><a href="https://ryota-murakami.github.io/"><img src="https://avatars2.githubusercontent.com/u/5501268?v=4" width="100px;" alt=""/><br /><sub><b>Ryota Murakami</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/commits?author=ryota-murakami" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/hottmanmichael"><img src="https://avatars3.githubusercontent.com/u/10534502?v=4" width="100px;" alt=""/><br /><sub><b>Michael Hottman</b></sub></a><br /><a href="#ideas-hottmanmichael" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://github.com/stevenfitzpatrick"><img src="https://avatars0.githubusercontent.com/u/23268855?v=4" width="100px;" alt=""/><br /><sub><b>Steven Fitzpatrick</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/issues?q=author%3Astevenfitzpatrick" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/juangl"><img src="https://avatars0.githubusercontent.com/u/1887029?v=4" width="100px;" alt=""/><br /><sub><b>Juan Je García</b></sub></a><br /><a href="https://github.com/testing-library/react-testing-library/commits?author=juangl" title="Documentation">📖</a></td>
</tr>
</table>
4 changes: 0 additions & 4 deletions cleanup-after-each.js

This file was deleted.

21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -5,19 +5,19 @@
"main": "dist/index.js",
"module": "dist/@testing-library/react.esm.js",
"engines": {
"node": ">=8"
"node": ">=10.18"
},
"scripts": {
"prebuild": "rimraf dist",
"build": "npm-run-all --parallel build:main build:bundle:main build:bundle:pure",
"build:main": "kcd-scripts build --no-clean",
"build:bundle:main": "kcd-scripts build --bundle --no-clean",
"build:bundle:pure": "cross-env BUILD_FILENAME_SUFFIX=.pure BUILD_INPUT=src/pure.js kcd-scripts build --bundle --no-clean",
"build:main": "kcd-scripts build --no-clean",
"lint": "kcd-scripts lint",
"setup": "npm install && npm run validate -s",
"test": "kcd-scripts test",
"test:update": "npm test -- --updateSnapshot --coverage",
"validate": "kcd-scripts validate",
"setup": "npm install && npm run validate -s"
"validate": "kcd-scripts validate"
},
"husky": {
"hooks": {
@@ -26,7 +26,6 @@
},
"files": [
"dist",
"cleanup-after-each.js",
"dont-cleanup-after-each.js",
"pure.js"
],
@@ -42,17 +41,17 @@
"end-to-end",
"e2e"
],
"author": "Kent C. Dodds <kent@doddsfamily.us> (http://kentcdodds.com/)",
"author": "Kent C. Dodds <me@kentcdodds.com> (https://kentcdodds.com)",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.8.4",
"@testing-library/dom": "^6.15.0",
"@types/testing-library__react": "^9.1.2"
"@babel/runtime": "^7.8.7",
"@testing-library/dom": "^7.0.2",
"@types/testing-library__react": "^9.1.3"
},
"devDependencies": {
"@reach/router": "^1.3.3",
"@testing-library/jest-dom": "^5.1.1",
"cross-env": "^7.0.1",
"cross-env": "^7.0.2",
"kcd-scripts": "^5.4.0",
"npm-run-all": "^4.1.5",
"react": "^16.9.0",
@@ -80,7 +79,7 @@
],
"repository": {
"type": "git",
"url": "https://github.com/testing-library/react-testing-library.git"
"url": "https://github.com/testing-library/react-testing-library"
},
"bugs": {
"url": "https://github.com/testing-library/react-testing-library/issues"
6 changes: 3 additions & 3 deletions src/__tests__/act.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import {render, fireEvent} from '../'
import {render, fireEvent, screen} from '../'

test('render calls useEffect immediately', () => {
const effectCb = jest.fn()
@@ -13,8 +13,8 @@ test('render calls useEffect immediately', () => {

test('findByTestId returns the element', async () => {
const ref = React.createRef()
const {findByTestId} = render(<div ref={ref} data-testid="foo" />)
expect(await findByTestId('foo')).toBe(ref.current)
render(<div ref={ref} data-testid="foo" />)
expect(await screen.findByTestId('foo')).toBe(ref.current)
})

test('fireEvent triggers useEffect calls', () => {
8 changes: 4 additions & 4 deletions src/__tests__/cleanup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import {render, cleanup} from '../'

test('cleans up the document', () => {
test('cleans up the document', async () => {
const spy = jest.fn()
const divId = 'my-div'

@@ -17,12 +17,12 @@ test('cleans up the document', () => {
}

render(<Test />)
cleanup()
await cleanup()
expect(document.body.innerHTML).toBe('')
expect(spy).toHaveBeenCalledTimes(1)
})

test('cleanup does not error when an element is not a child', () => {
test('cleanup does not error when an element is not a child', async () => {
render(<div />, {container: document.createElement('div')})
cleanup()
await cleanup()
})
6 changes: 3 additions & 3 deletions src/__tests__/debug.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import {render} from '../'
import {render, screen} from '../'

beforeEach(() => {
jest.spyOn(console, 'log').mockImplementation(() => {})
@@ -26,8 +26,8 @@ test('debug pretty prints multiple containers', () => {
<h1 data-testid="testId">Hello World</h1>
</>
)
const {getAllByTestId, debug} = render(<HelloWorld />)
const multipleElements = getAllByTestId('testId')
const {debug} = render(<HelloWorld />)
const multipleElements = screen.getAllByTestId('testId')
debug(multipleElements)

expect(console.log).toHaveBeenCalledTimes(2)
12 changes: 5 additions & 7 deletions src/__tests__/end-to-end.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import {render, wait} from '../'
import {render, waitForElementToBeRemoved, screen} from '../'

const fetchAMessage = () =>
new Promise(resolve => {
@@ -30,10 +30,8 @@ class ComponentWithLoader extends React.Component {
}

test('it waits for the data to be loaded', async () => {
const {queryByText, queryByTestId} = render(<ComponentWithLoader />)

expect(queryByText('Loading...')).toBeTruthy()

await wait(() => expect(queryByText('Loading...')).toBeNull())
expect(queryByTestId('message').textContent).toMatch(/Hello World/)
render(<ComponentWithLoader />)
const loading = () => screen.getByText('Loading...')
await waitForElementToBeRemoved(loading)
expect(screen.getByTestId('message')).toHaveTextContent(/Hello World/)
})
12 changes: 6 additions & 6 deletions src/__tests__/render.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import ReactDOM from 'react-dom'
import {render} from '../'
import {render, screen} from '../'

test('renders div into document', () => {
const ref = React.createRef()
@@ -39,9 +39,9 @@ test('works great with react portals', () => {
)
}

const {unmount, getByTestId, getByText} = render(<MyPortal />)
expect(getByText('Hello World')).toBeInTheDocument()
const portalNode = getByTestId('my-portal')
const {unmount} = render(<MyPortal />)
expect(screen.getByText('Hello World')).toBeInTheDocument()
const portalNode = screen.getByTestId('my-portal')
expect(portalNode).toBeInTheDocument()
unmount()
expect(portalNode).not.toBeInTheDocument()
@@ -72,11 +72,11 @@ test('renders options.wrapper around node', () => {
<div data-testid="wrapper">{children}</div>
)

const {container, getByTestId} = render(<div data-testid="inner" />, {
const {container} = render(<div data-testid="inner" />, {
wrapper: WrapperComponent,
})

expect(getByTestId('wrapper')).toBeInTheDocument()
expect(screen.getByTestId('wrapper')).toBeInTheDocument()
expect(container.firstChild).toMatchInlineSnapshot(`
<div
data-testid="wrapper"
11 changes: 6 additions & 5 deletions src/__tests__/stopwatch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import {render, fireEvent} from '../'
import {render, fireEvent, screen} from '../'

class StopWatch extends React.Component {
state = {lapse: 0, running: false}
@@ -37,12 +37,12 @@ class StopWatch extends React.Component {
}
}

const wait = time => new Promise(resolve => setTimeout(resolve, time))
const sleep = t => new Promise(resolve => setTimeout(resolve, t))

test('unmounts a component', async () => {
jest.spyOn(console, 'error').mockImplementation(() => {})
const {unmount, getByText, container} = render(<StopWatch />)
fireEvent.click(getByText('Start'))
const {unmount, container} = render(<StopWatch />)
fireEvent.click(screen.getByText('Start'))
unmount()
// hey there reader! You don't need to have an assertion like this one
// this is just me making sure that the unmount function works.
@@ -51,6 +51,7 @@ test('unmounts a component', async () => {
// just wait to see if the interval is cleared or not
// if it's not, then we'll call setState on an unmounted component
// and get an error.
await sleep(5)
// eslint-disable-next-line no-console
await wait(() => expect(console.error).not.toHaveBeenCalled())
expect(console.error).not.toHaveBeenCalled()
})
4 changes: 1 addition & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import flush from './flush-microtasks'
import {cleanup} from './pure'

// if we're running in a test runner that supports afterEach
@@ -8,8 +7,7 @@ import {cleanup} from './pure'
// or set the RTL_SKIP_AUTO_CLEANUP env variable to 'true'.
if (typeof afterEach === 'function' && !process.env.RTL_SKIP_AUTO_CLEANUP) {
afterEach(async () => {
await flush()
cleanup()
await cleanup()
})
}

8 changes: 5 additions & 3 deletions src/pure.js
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import {
configure as configureDTL,
} from '@testing-library/dom'
import act, {asyncAct} from './act-compat'
import flush from './flush-microtasks'

configureDTL({
asyncWrapper: async cb => {
@@ -88,7 +89,8 @@ function render(
}
}

function cleanup() {
async function cleanup() {
await flush()
mountedContainers.forEach(cleanupAtContainer)
}

@@ -105,8 +107,8 @@ function cleanupAtContainer(container) {
// react-testing-library's version of fireEvent will call
// dom-testing-library's version of fireEvent wrapped inside
// an "act" call so that after all event callbacks have been
// been called, the resulting useEffect callbacks will also
// be called.
// called, the resulting useEffect callbacks will also be
// called.
function fireEvent(...args) {
let returnValue
act(() => {