diff --git a/.gitattributes b/.gitattributes index 391f0a4e..6313b56c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1 @@ -* text=auto -*.js text eol=lf +* text=auto eol=lf diff --git a/.gitignore b/.gitignore index 5bb9facf..8e0c70cb 100644 --- a/.gitignore +++ b/.gitignore @@ -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 - diff --git a/.prettierignore b/.prettierignore index 30117ea2..9c628283 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,3 @@ -package.json node_modules -dist coverage +dist diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index f3685197..00000000 --- a/.prettierrc +++ /dev/null @@ -1,11 +0,0 @@ -{ - "printWidth": 80, - "tabWidth": 2, - "useTabs": false, - "semi": false, - "singleQuote": true, - "trailingComma": "all", - "bracketSpacing": false, - "jsxBracketSameLine": false, - "proseWrap": "always" -} diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 00000000..4679d9bf --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1 @@ +module.exports = require('kcd-scripts/prettier') diff --git a/.travis.yml b/.travis.yml index b670635e..2da1648c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ cache: npm notifications: email: false node_js: - - 10.14 + - 10.18 - 12 - node install: diff --git a/package.json b/package.json index cb29c210..6ec8284a 100644 --- a/package.json +++ b/package.json @@ -5,19 +5,19 @@ "main": "dist/index.js", "module": "dist/@testing-library/react.esm.js", "engines": { - "node": ">=10" + "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": { @@ -41,7 +41,7 @@ "end-to-end", "e2e" ], - "author": "Kent C. Dodds (http://kentcdodds.com/)", + "author": "Kent C. Dodds (https://kentcdodds.com)", "license": "MIT", "dependencies": { "@babel/runtime": "^7.8.7", @@ -51,7 +51,7 @@ "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", @@ -79,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" diff --git a/src/__tests__/act.js b/src/__tests__/act.js index 2adcee94..97438d77 100644 --- a/src/__tests__/act.js +++ b/src/__tests__/act.js @@ -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(
) - expect(await findByTestId('foo')).toBe(ref.current) + render(
) + expect(await screen.findByTestId('foo')).toBe(ref.current) }) test('fireEvent triggers useEffect calls', () => { diff --git a/src/__tests__/debug.js b/src/__tests__/debug.js index 48411d88..088385b7 100644 --- a/src/__tests__/debug.js +++ b/src/__tests__/debug.js @@ -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', () => {

Hello World

) - const {getAllByTestId, debug} = render() - const multipleElements = getAllByTestId('testId') + const {debug} = render() + const multipleElements = screen.getAllByTestId('testId') debug(multipleElements) expect(console.log).toHaveBeenCalledTimes(2) diff --git a/src/__tests__/end-to-end.js b/src/__tests__/end-to-end.js index 4cdfc328..cbbf0973 100644 --- a/src/__tests__/end-to-end.js +++ b/src/__tests__/end-to-end.js @@ -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() - - expect(queryByText('Loading...')).toBeTruthy() - - await wait(() => expect(queryByText('Loading...')).toBeNull()) - expect(queryByTestId('message').textContent).toMatch(/Hello World/) + render() + const loading = () => screen.getByText('Loading...') + await waitForElementToBeRemoved(loading) + expect(screen.getByTestId('message')).toHaveTextContent(/Hello World/) }) diff --git a/src/__tests__/render.js b/src/__tests__/render.js index 28d7f9e7..54916ba4 100644 --- a/src/__tests__/render.js +++ b/src/__tests__/render.js @@ -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() - expect(getByText('Hello World')).toBeInTheDocument() - const portalNode = getByTestId('my-portal') + const {unmount} = render() + 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', () => {
{children}
) - const {container, getByTestId} = render(
, { + const {container} = render(
, { wrapper: WrapperComponent, }) - expect(getByTestId('wrapper')).toBeInTheDocument() + expect(screen.getByTestId('wrapper')).toBeInTheDocument() expect(container.firstChild).toMatchInlineSnapshot(`
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() - fireEvent.click(getByText('Start')) + const {unmount, container} = render() + 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() })