Skip to content

Commit f26b8df

Browse files
Kent C. Doddskentcdodds
Kent C. Dodds
authored andcommitted
chore: cleanup repo (#600)
1 parent 7942f68 commit f26b8df

12 files changed

+34
-53
lines changed

.gitattributes

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
* text=auto
2-
*.js text eol=lf
1+
* text=auto eol=lf

.gitignore

-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
node_modules
22
coverage
33
dist
4-
.opt-in
5-
.opt-out
64
.DS_Store
7-
.eslintcache
8-
9-
yarn-error.log
105

116
# these cause more harm than good
127
# when working with contributors
138
package-lock.json
149
yarn.lock
15-

.prettierignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
package.json
21
node_modules
3-
dist
42
coverage
3+
dist

.prettierrc

-11
This file was deleted.

.prettierrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('kcd-scripts/prettier')

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cache: npm
33
notifications:
44
email: false
55
node_js:
6-
- 10.14
6+
- 10.18
77
- 12
88
- node
99
install:

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
"main": "dist/index.js",
66
"module": "dist/@testing-library/react.esm.js",
77
"engines": {
8-
"node": ">=10"
8+
"node": ">=10.18"
99
},
1010
"scripts": {
1111
"prebuild": "rimraf dist",
1212
"build": "npm-run-all --parallel build:main build:bundle:main build:bundle:pure",
13-
"build:main": "kcd-scripts build --no-clean",
1413
"build:bundle:main": "kcd-scripts build --bundle --no-clean",
1514
"build:bundle:pure": "cross-env BUILD_FILENAME_SUFFIX=.pure BUILD_INPUT=src/pure.js kcd-scripts build --bundle --no-clean",
15+
"build:main": "kcd-scripts build --no-clean",
1616
"lint": "kcd-scripts lint",
17+
"setup": "npm install && npm run validate -s",
1718
"test": "kcd-scripts test",
1819
"test:update": "npm test -- --updateSnapshot --coverage",
19-
"validate": "kcd-scripts validate",
20-
"setup": "npm install && npm run validate -s"
20+
"validate": "kcd-scripts validate"
2121
},
2222
"husky": {
2323
"hooks": {
@@ -41,7 +41,7 @@
4141
"end-to-end",
4242
"e2e"
4343
],
44-
"author": "Kent C. Dodds <[email protected]> (http://kentcdodds.com/)",
44+
"author": "Kent C. Dodds <[email protected]> (https://kentcdodds.com)",
4545
"license": "MIT",
4646
"dependencies": {
4747
"@babel/runtime": "^7.8.7",
@@ -51,7 +51,7 @@
5151
"devDependencies": {
5252
"@reach/router": "^1.3.3",
5353
"@testing-library/jest-dom": "^5.1.1",
54-
"cross-env": "^7.0.1",
54+
"cross-env": "^7.0.2",
5555
"kcd-scripts": "^5.4.0",
5656
"npm-run-all": "^4.1.5",
5757
"react": "^16.9.0",
@@ -79,7 +79,7 @@
7979
],
8080
"repository": {
8181
"type": "git",
82-
"url": "https://github.com/testing-library/react-testing-library.git"
82+
"url": "https://github.com/testing-library/react-testing-library"
8383
},
8484
"bugs": {
8585
"url": "https://github.com/testing-library/react-testing-library/issues"

src/__tests__/act.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import {render, fireEvent} from '../'
2+
import {render, fireEvent, screen} from '../'
33

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

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

2020
test('fireEvent triggers useEffect calls', () => {

src/__tests__/debug.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import {render} from '../'
2+
import {render, screen} from '../'
33

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

3333
expect(console.log).toHaveBeenCalledTimes(2)

src/__tests__/end-to-end.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import {render, wait} from '../'
2+
import {render, waitForElementToBeRemoved, screen} from '../'
33

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

3232
test('it waits for the data to be loaded', async () => {
33-
const {queryByText, queryByTestId} = render(<ComponentWithLoader />)
34-
35-
expect(queryByText('Loading...')).toBeTruthy()
36-
37-
await wait(() => expect(queryByText('Loading...')).toBeNull())
38-
expect(queryByTestId('message').textContent).toMatch(/Hello World/)
33+
render(<ComponentWithLoader />)
34+
const loading = () => screen.getByText('Loading...')
35+
await waitForElementToBeRemoved(loading)
36+
expect(screen.getByTestId('message')).toHaveTextContent(/Hello World/)
3937
})

src/__tests__/render.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22
import ReactDOM from 'react-dom'
3-
import {render} from '../'
3+
import {render, screen} from '../'
44

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

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

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

79-
expect(getByTestId('wrapper')).toBeInTheDocument()
79+
expect(screen.getByTestId('wrapper')).toBeInTheDocument()
8080
expect(container.firstChild).toMatchInlineSnapshot(`
8181
<div
8282
data-testid="wrapper"

src/__tests__/stopwatch.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import {render, fireEvent} from '../'
2+
import {render, fireEvent, screen} from '../'
33

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

40-
const wait = time => new Promise(resolve => setTimeout(resolve, time))
40+
const sleep = t => new Promise(resolve => setTimeout(resolve, t))
4141

4242
test('unmounts a component', async () => {
4343
jest.spyOn(console, 'error').mockImplementation(() => {})
44-
const {unmount, getByText, container} = render(<StopWatch />)
45-
fireEvent.click(getByText('Start'))
44+
const {unmount, container} = render(<StopWatch />)
45+
fireEvent.click(screen.getByText('Start'))
4646
unmount()
4747
// hey there reader! You don't need to have an assertion like this one
4848
// this is just me making sure that the unmount function works.
@@ -51,6 +51,7 @@ test('unmounts a component', async () => {
5151
// just wait to see if the interval is cleared or not
5252
// if it's not, then we'll call setState on an unmounted component
5353
// and get an error.
54+
await sleep(5)
5455
// eslint-disable-next-line no-console
55-
await wait(() => expect(console.error).not.toHaveBeenCalled())
56+
expect(console.error).not.toHaveBeenCalled()
5657
})

0 commit comments

Comments
 (0)