Closed
Description
react-testing-library
version: 4.1.3react
version: 16.4.1node
version: 8.11.1yarn
version: 1.6.0jsdom
version: 11.11.0
Relevant code or config:
/* eslint-disable */
import React, {Component} from 'react'
import {render, waitForElement, cleanup} from 'react-testing-library'
import {expect} from 'chai'
class Foobar extends Component {
constructor (props) {
super(props)
this.state = {showThing: false}
}
componentDidMount () {
setTimeout(() => this.setState({showThing: true}), 100)
}
render () {
return (
<div>
Hello world
<a>Link</a>
{this.state.showThing && <div data-testid='thing' >Thing</div>}
</div>
)
}
}
describe('react-testing-library bugs', () => {
afterEach(cleanup)
it('should not barf on MutationObserver being undefined', async () => {
const {getByTestId} = render(<Foobar />)
const thingNode = await waitForElement(() => getByTestId('thing'))
expect(thingNode).to.not.be.null
})
it('should not barf on Node being undefined', async () => {
const {getByText} = render(<Foobar />)
const linkNode = getByText('Link')
expect(linkNode).to.not.be.null
})
})
// my mocha test_helper.js
import jsdom from 'jsdom'
const dom = new jsdom.JSDOM('<!doctype html><html><body></body></html>')
global.window = dom.window
global.document = dom.window.document
global.navigator = dom.window.navigator
What you did:
Attempting to use waitForElement
and getByText
.
What happened:
1) react-testing-library bugs
should not barf on MutationObserver being undefined:
ReferenceError: MutationObserver is not defined
at /Users/davidadams/Code/react-testing-library-bug/node_modules/dom-testing-library/dist/wait-for-element.js:61:5
at new Promise (node_modules/core-js/modules/es6.promise.js:177:7)
at waitForElement (node_modules/dom-testing-library/dist/wait-for-element.js:26:10)
at _callee$ (test/broken-test.js:29:29)
at tryCatch (node_modules/regenerator-runtime/runtime.js:65:40)
at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:303:22)
at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:117:21)
at step (test/broken-test.js:15:191)
at /Users/davidadams/Code/react-testing-library-bug/test/broken-test.js:15:437
at new Promise (node_modules/core-js/modules/es6.promise.js:177:7)
at Context.<anonymous> (test/broken-test.js:15:99)
2) react-testing-library bugs
should not barf on Node being undefined:
ReferenceError: Node is not defined
at /Users/davidadams/Code/react-testing-library-bug/node_modules/dom-testing-library/dist/get-node-text.js:8:31
at Array.filter (<anonymous>)
at getNodeText (node_modules/dom-testing-library/dist/get-node-text.js:7:38)
at /Users/davidadams/Code/react-testing-library-bug/node_modules/dom-testing-library/dist/queries.js:99:49
at Array.filter (<anonymous>)
at queryAllByText (node_modules/dom-testing-library/dist/queries.js:98:59)
at getAllByText (node_modules/dom-testing-library/dist/queries.js:259:28)
at firstResultOrNull (node_modules/dom-testing-library/dist/query-helpers.js:37:30)
at getByText (node_modules/dom-testing-library/dist/queries.js:271:42)
at _callee2$ (test/broken-test.js:35:22)
at tryCatch (node_modules/regenerator-runtime/runtime.js:65:40)
at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:303:22)
at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:117:21)
at step (test/broken-test.js:15:191)
at /Users/davidadams/Code/react-testing-library-bug/test/broken-test.js:15:437
at new Promise (node_modules/core-js/modules/es6.promise.js:177:7)
at Context.<anonymous> (test/broken-test.js:15:99)
Reproduction:
I've created a barebones repo that illustrates the problem.
Problem description:
I believe the problem is jsdom and the fact that i'm not using jest. I'm using mocha. It appears that maybe jest polyfills some of these browser apis(?)
Suggested solution:
Provide instructions for non-jest users.