Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In upgrading to 1.0.5, tests seem to be breaking due to missing globals of jsdom? #2342

Closed
kellyrmilligan opened this issue May 23, 2017 · 12 comments

Comments

@kellyrmilligan
Copy link
Contributor

If you are reporting a bug, please fill in below. Otherwise feel free to remove this template entirely.

Can you reproduce the problem with latest npm?

yes
Many errors, especially related to "missing modules", are due to npm bugs.

If you're using Windows, follow these instructions to update npm.

If you're using OS X or Linux, run this to update npm:

npm install -g npm@latest

cd your_project_directory
rm -rf node_modules
npm install

Then try to reproduce the issue again.

Can you still reproduce it?

Description

on upgrading to latest 1.0 release, a few tests are breaking that previously passed.

The first test that breaks throws an error on

document.getElementId call, getting TypeError: Cannot read property 'getElementById' of undefined shouldn't this be defined by jsdom?

second one is similar in nature, although it's calling it as a global without prefixing it with window.

i'm trying to track down the differences from the 0.9x stuff and 1.0. the rest of the tests I have are passing quite nicely.

Expected behavior

document should exist in the test env.

Actual behavior

Its not there.

Environment

Run these commands in the project folder and fill in their results:

  1. npm ls react-scripts: react-scripts@1.0.5
  2. node -v: v6.9.2
  3. npm -v: 3.10.9

Then, specify:

  1. Operating system: OS X
  2. Browser and version:

Reproducible Demo

Please take the time to create a new app that reproduces the issue.

Alternatively, you could copy your app that experiences the problem and start removing things until you’re left with the minimal reproducible demo.

(Accidentally, you might get to the root of your problem during that process.)

Push to GitHub and paste the link here.

By doing this, you're helping the Create React App contributors a big time!
Demonstrable issues gets fixed faster.

@gaearon
Copy link
Contributor

gaearon commented May 23, 2017

Can you reproduce this on an empty project?

@kellyrmilligan
Copy link
Contributor Author

ok, I think I am just seeing a weird stack trace. the new test.js script throws errors on unhandledRejection and it looks like my project has a few of those in the component tests where i'm not fully mocking out requests that happen, as I was more focused on mocking those out in the redux actions instead. guess I need to clean up a few things.

is this change mentioned in the notes?

@kellyrmilligan
Copy link
Contributor Author

#1819

@kellyrmilligan
Copy link
Contributor Author

that seems more like a breaking change to me FYI, but my tests will be more accurate as a result :)

@gaearon
Copy link
Contributor

gaearon commented May 23, 2017

Ah, didn’t realize that’s technically a breaking change, thanks. I’ll add to the release notes.

@kellyrmilligan
Copy link
Contributor Author

👍

@kellyrmilligan
Copy link
Contributor Author

ok, well, after trying to get my last couple of tests passing, I am seeing what I think is an issue. I can't tell if its how jest is setting up jsdom, or what. I can post in the jest repo as well.

https://github.com/kellyrmilligan/reacttestingexamplebug

comment out the react-modal component and look at the console logging. document becomes undefined after the async fetch call fails and calls setState again.

componentDidMount () {
    this.setState({
      isLoading: true
    })

  this.makeRequest()
      .then(() => {
        this.setState({
          isLoading: false,
        })
      }, () => {
	this.setState({
          isLoading: false
        })
     })
}

any ideas on this?

@gaearon
Copy link
Contributor

gaearon commented May 25, 2017

Tagging this as needing investigation by someone motivated.

@kellyrmilligan
Copy link
Contributor Author

appreciate it, I have to skip a few tests with the upgrade.

@kellyrmilligan
Copy link
Contributor Author

I can also re-post in jest, as i'm guessing that may be better suited to this.

@gaearon
Copy link
Contributor

gaearon commented May 25, 2017

If you do, it would be great if you could provide an isolated example without CRA for them.
For example you could try https://repl.it/languages/jest.

@gaearon
Copy link
Contributor

gaearon commented Jun 22, 2017

I am guessing that your test is synchronous, but app code is asynchronous. The test doesn't wait for app to finish, and so funky things can happen. Try changing your test to wait for the async app code to complete. There are examples in Jest docs for how to write async tests.

If this doesn't help please let me know and we can reopen. In general it's better to report such things directly to Jest. Cheers!

@gaearon gaearon closed this as completed Jun 22, 2017
@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants