Skip to content

Commit c9be668

Browse files
author
Kent C. Dodds
committed
test: fix everything
1 parent 9834de2 commit c9be668

18 files changed

+30
-91
lines changed

CONTRIBUTING.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,6 @@ Thanks for being willing to contribute!
2727
> branch. Whenever you want to update your version of `master`, do a regular
2828
> `git pull`.
2929
30-
## Add yourself as a contributor
31-
32-
This project follows the [all contributors][all-contributors] specification.
33-
To add yourself to the table of contributors on the `README.md`, please use the
34-
automated script as part of your PR:
35-
36-
```console
37-
npm run add-contributor
38-
```
39-
40-
Follow the prompt and commit `.all-contributorsrc` and `README.md` in the PR.
41-
If you've already added yourself to the list and are making
42-
a new type of contribution, you can run it again and select the added
43-
contribution type.
44-
4530
## Committing and Pushing changes
4631
4732
Please make sure to run the tests before you commit your changes. You can run

jest.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ module.exports = {
1515
testEnvironment: 'jest-environment-node',
1616
},
1717
],
18+
watchPlugins: [
19+
require.resolve('jest-watch-select-projects'),
20+
...baseConfig.watchPlugins,
21+
],
1822
// this is for eslint
1923
modulePaths: baseConfig.modulePaths,
2024
}

package.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,36 @@
2424
"node": ">=8"
2525
},
2626
"scripts": {
27-
"add-contributor": "kcd-scripts contributors add",
2827
"build": "kcd-scripts build && kcd-scripts build --bundle --no-clean",
2928
"lint": "kcd-scripts lint",
3029
"test": "kcd-scripts test",
3130
"test:update": "npm test -- --updateSnapshot --coverage",
3231
"validate": "kcd-scripts validate",
3332
"setup": "npm install && npm run validate -s",
34-
"precommit": "kcd-scripts precommit",
3533
"dtslint": "dtslint typings"
3634
},
35+
"husky": {
36+
"hooks": {
37+
"pre-commit": "kcd-scripts pre-commit"
38+
}
39+
},
3740
"files": [
3841
"dist",
3942
"typings"
4043
],
4144
"dependencies": {
42-
"@babel/runtime": "^7.1.5",
45+
"@babel/runtime": "^7.3.4",
4346
"@sheerun/mutationobserver-shim": "^0.3.2",
4447
"pretty-format": "^24.0.0",
4548
"wait-for-expect": "^1.1.0"
4649
},
4750
"devDependencies": {
48-
"dtslint": "^0.3.0",
49-
"jest-dom": "^2.1.1",
51+
"dtslint": "^0.5.3",
52+
"jest-dom": "^3.1.2",
5053
"jest-in-case": "^1.0.2",
51-
"jsdom": "^13.0.0",
52-
"kcd-scripts": "^0.46.0"
54+
"jest-watch-select-projects": "^0.1.1",
55+
"jsdom": "^13.2.0",
56+
"kcd-scripts": "^1.1.0"
5357
},
5458
"eslintConfig": {
5559
"extends": "./node_modules/kcd-scripts/eslint.js",

src/__tests__/element-queries.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'jest-dom/extend-expect'
22
import {configure} from '../config'
33
import {render, renderIntoDocument} from './helpers/test-utils'
4-
import document from './helpers/document'
54

65
beforeEach(() => {
76
document.defaultView.Cypress = null

src/__tests__/events.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import {fireEvent} from '..'
2-
import document from './helpers/document'
3-
import window from './helpers/window'
42

53
const eventTypes = [
64
{

src/__tests__/example.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import {getByLabelText, getByText, getByTestId, queryByTestId, wait} from '../'
33
// adds special assertions like toHaveTextContent
44
import 'jest-dom/extend-expect'
5-
import document from './helpers/document'
65

76
function getExampleDOM() {
87
// This is just a raw example of setting up some DOM

src/__tests__/get-queries-for-element.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {getQueriesForElement} from '../get-queries-for-element'
22
import {queries} from '..'
3-
import document from './helpers/document'
43

54
test('uses default queries', () => {
65
const container = document.createElement('div')

src/__tests__/helpers.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
import {getDocument, newMutationObserver} from '../helpers'
22

3-
describe('getDocument', () => {
4-
if (typeof document === 'undefined') {
5-
test('throws an error if window does not exist', () => {
6-
expect(() => getDocument()).toThrowError(
7-
/Could not find default container/,
8-
)
9-
})
10-
} else {
11-
test('returns global document if exists', () => {
12-
expect(getDocument()).toBe(document)
13-
})
14-
}
3+
test('returns global document if exists', () => {
4+
expect(getDocument()).toBe(document)
155
})
166

177
class DummyClass {

src/__tests__/helpers/document.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/__tests__/helpers/test-utils.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {getQueriesForElement} from '../../get-queries-for-element'
2-
import document from './document'
32

43
function render(html) {
54
const container = document.createElement('div')

src/__tests__/helpers/window.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/__tests__/pretty-dom.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {prettyDOM} from '../pretty-dom'
22
import {render} from './helpers/test-utils'
3-
import document from './helpers/document'
43

54
test('it prints out the given DOM element tree', () => {
65
const {container} = render('<div>Hello World!</div>')

src/__tests__/wait-for-dom-change.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {waitForDomChange} from '../'
22
// adds special assertions like toBeTruthy
33
import 'jest-dom/extend-expect'
44
import {render} from './helpers/test-utils'
5-
import document from './helpers/document'
65

76
const skipSomeTime = delayMs =>
87
new Promise(resolve => setTimeout(resolve, delayMs))
@@ -16,11 +15,7 @@ test('it waits for the next DOM mutation', async () => {
1615
const successHandler = jest.fn().mockName('successHandler')
1716
const errorHandler = jest.fn().mockName('errorHandler')
1817

19-
if (typeof window === 'undefined') {
20-
waitForDomChange({container: document}).then(successHandler, errorHandler)
21-
} else {
22-
waitForDomChange().then(successHandler, errorHandler)
23-
}
18+
waitForDomChange().then(successHandler, errorHandler)
2419

2520
// Promise callbacks are always asynchronous.
2621
expect(successHandler).toHaveBeenCalledTimes(0)
@@ -88,14 +83,7 @@ test('it throws if timeout is exceeded', async () => {
8883
const successHandler = jest.fn().mockName('successHandler')
8984
const errorHandler = jest.fn().mockName('errorHandler')
9085

91-
if (typeof window === 'undefined') {
92-
waitForDomChange({container: document, timeout: 70}).then(
93-
successHandler,
94-
errorHandler,
95-
)
96-
} else {
97-
waitForDomChange({timeout: 70}).then(successHandler, errorHandler)
98-
}
86+
waitForDomChange({timeout: 70}).then(successHandler, errorHandler)
9987

10088
await skipSomeTimeForMutationObserver(100)
10189

src/__tests__/wait-for-element-to-be-removed.fake-timers.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ import {render} from './helpers/test-utils'
44

55
jest.useFakeTimers()
66

7-
// const skipSomeTimeForMutationObserver = (delayMs = 50) => {
8-
// jest.advanceTimersByTime(delayMs)
9-
// jest.runAllImmediates()
10-
// }
11-
127
test('requires a function as the first parameter', () => {
138
return expect(
149
waitForElementToBeRemoved(),

src/__tests__/wait-for-element.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {waitForElement, wait} from '../'
22
// adds special assertions like toBeTruthy
33
import 'jest-dom/extend-expect'
44
import {render} from './helpers/test-utils'
5-
import document from './helpers/document'
65

76
const skipSomeTime = delayMs =>
87
new Promise(resolve => setTimeout(resolve, delayMs))

src/__tests__/wait.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,3 @@ test('it waits for the data to be loaded', async () => {
1010
await wait(() => expect(spy).toHaveBeenCalledTimes(1))
1111
expect(spy).toHaveBeenCalledWith()
1212
})
13-
14-
test('can just be used for a next tick thing', async () => {
15-
jest.useFakeTimers()
16-
const spy = jest.fn()
17-
Promise.resolve().then(spy)
18-
expect(spy).toHaveBeenCalledTimes(0) // promises are always async
19-
await wait() // wait for next tick
20-
jest.advanceTimersByTime(60)
21-
expect(spy).toHaveBeenCalledTimes(1)
22-
jest.clearAllTimers()
23-
})

src/helpers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function newMutationObserver(onMutation) {
1111
}
1212

1313
function getDocument() {
14+
/* istanbul ignore if */
1415
if (typeof window === 'undefined') {
1516
throw new Error('Could not find default container')
1617
}

tests/setup-env.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import MutationObserver from '@sheerun/mutationobserver-shim'
2+
3+
if (typeof window === 'undefined') {
4+
const {JSDOM} = require('jsdom')
5+
const dom = new JSDOM()
6+
global.window = dom.window
7+
global.document = dom.window.document
8+
global.window.Date = Date
9+
window.MutationObserver = MutationObserver
10+
}

0 commit comments

Comments
 (0)