Skip to content

Commit

Permalink
chore: cleanup repo (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kent C. Dodds authored and kentcdodds committed Mar 12, 2020
1 parent 7942f68 commit f26b8df
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 53 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
6 changes: 0 additions & 6 deletions .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

3 changes: 1 addition & 2 deletions .prettierignore
@@ -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
@@ -0,0 +1 @@
module.exports = require('kcd-scripts/prettier')
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -3,7 +3,7 @@ cache: npm
notifications:
email: false
node_js:
- 10.14
- 10.18
- 12
- node
install:
Expand Down
14 changes: 7 additions & 7 deletions package.json
Expand Up @@ -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": {
Expand All @@ -41,7 +41,7 @@
"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.7",
Expand All @@ -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",
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions 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()
Expand All @@ -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', () => {
Expand Down
6 changes: 3 additions & 3 deletions 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(() => {})
Expand All @@ -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)
Expand Down
12 changes: 5 additions & 7 deletions 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 => {
Expand Down Expand Up @@ -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
@@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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"
Expand Down
11 changes: 6 additions & 5 deletions src/__tests__/stopwatch.js
@@ -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}
Expand Down Expand Up @@ -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.
Expand All @@ -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()
})

0 comments on commit f26b8df

Please sign in to comment.