Skip to content

Commit ba68f8d

Browse files
author
Kent C. Dodds
committed
Revert "fix(node): allow running in node environment (testing-library#114)"
This reverts commit 1b12385.
1 parent 1b12385 commit ba68f8d

15 files changed

+122
-173
lines changed

.size-snapshot.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dist/dom-testing-library.umd.js": {
3-
"bundled": 144335,
4-
"minified": 52790,
5-
"gzipped": 15639
3+
"bundled": 115443,
4+
"minified": 50960,
5+
"gzipped": 15294
66
}
77
}

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const jestConfig = require('kcd-scripts/jest')
22

33
module.exports = Object.assign(jestConfig, {
4-
testEnvironment: 'jest-environment-node',
4+
testEnvironment: 'jest-environment-jsdom',
55
})

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
"build": "kcd-scripts build && kcd-scripts build --bundle umd --no-clean",
2828
"lint": "kcd-scripts lint",
2929
"test": "kcd-scripts test",
30-
"test:all": "npm test && npm test -- --env jsdom",
3130
"test:update": "npm test -- --updateSnapshot --coverage",
32-
"validate": "kcd-scripts validate build,lint,test:all",
31+
"validate": "kcd-scripts validate",
3332
"setup": "npm install && npm run validate -s",
3433
"precommit": "kcd-scripts precommit",
3534
"dtslint": "dtslint typings"
@@ -39,15 +38,14 @@
3938
"typings"
4039
],
4140
"dependencies": {
42-
"@sheerun/mutationobserver-shim": "^0.3.2",
41+
"mutationobserver-shim": "^0.3.2",
4342
"pretty-format": "^23.6.0",
4443
"wait-for-expect": "^1.0.0"
4544
},
4645
"devDependencies": {
4746
"dtslint": "^0.3.0",
48-
"jest-dom": "^2.0.4",
47+
"jest-dom": "^1.7.0",
4948
"jest-in-case": "^1.0.2",
50-
"jsdom": "^12.2.0",
5149
"kcd-scripts": "^0.41.0",
5250
"microbundle": "^0.4.4"
5351
},

src/__tests__/element-queries.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import 'jest-dom/extend-expect'
22
import {render} from './helpers/test-utils'
3-
import document from './helpers/document'
43

54
beforeEach(() => {
6-
document.defaultView.Cypress = null
5+
window.Cypress = null
76
})
87

98
test('query can return null', () => {
@@ -149,7 +148,9 @@ test('get element by its alt text', () => {
149148
<img alt="finding nemo poster" src="/finding-nemo.png" />
150149
</div>,
151150
`)
152-
expect(getByAltText(/fin.*nem.*poster$/i).src).toContain('/finding-nemo.png')
151+
expect(getByAltText(/fin.*nem.*poster$/i).src).toBe(
152+
'http://localhost/finding-nemo.png',
153+
)
153154
})
154155

155156
test('query/get element by its title', () => {
@@ -488,7 +489,7 @@ test('test the debug helper prints the dom state here', () => {
488489
})
489490

490491
test('get throws a useful error message without DOM in Cypress', () => {
491-
document.defaultView.Cypress = {}
492+
window.Cypress = {}
492493
const {
493494
getByLabelText,
494495
getBySelectText,

src/__tests__/events.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {fireEvent} from '..'
2-
import document from './helpers/document'
32

43
const eventTypes = [
54
{
@@ -172,7 +171,7 @@ test('assigning a value to a target that cannot have a value throws an error', (
172171

173172
test('assigning the files property on an input', () => {
174173
const node = document.createElement('input')
175-
const file = new document.defaultView.File(['(⌐□_□)'], 'chucknorris.png', {
174+
const file = new File(['(⌐□_□)'], 'chucknorris.png', {
176175
type: 'image/png',
177176
})
178177
fireEvent.change(node, {target: {files: [file]}})

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/document.js

Lines changed: 0 additions & 35 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__/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-element.js

Lines changed: 1 addition & 11 deletions
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
async function skipSomeTime(delayMs) {
87
await new Promise(resolve => setTimeout(resolve, delayMs))
@@ -105,16 +104,7 @@ test('it waits for the next DOM mutation with default callback', async () => {
105104
const successHandler = jest.fn().mockName('successHandler')
106105
const errorHandler = jest.fn().mockName('errorHandler')
107106

108-
let promise
109-
110-
if (typeof window !== 'undefined' && typeof window.document !== 'undefined') {
111-
promise = waitForElement().then(successHandler, errorHandler)
112-
} else {
113-
promise = waitForElement(undefined, {container: document}).then(
114-
successHandler,
115-
errorHandler,
116-
)
117-
}
107+
const promise = waitForElement().then(successHandler, errorHandler)
118108

119109
// Promise callbacks are always asynchronous.
120110
expect(successHandler).toHaveBeenCalledTimes(0)

0 commit comments

Comments
 (0)