jest icon indicating copy to clipboard operation
jest copied to clipboard

Since Jest update, Response is not defined for more than one file.

Open audetpascale opened this issue 10 years ago • 10 comments

Hi,

I have migrated Jest from 0.8.2 to 0.10.2. I have fixed the small issues I had, except for one.

At this point, I have two API utils files (Flux architecture). To communicate with the REST API, I use the Fetch API, with whatwg-fetch as polyfill. So, to mock the request, I create a Response, as defined in the Fetch API.

Example:

fetch.mockReturnValueOnce(Promise.resolve(new Response(
    '',
    {
        status: 204
    }
)));

If I run the two files individually, they pass. If I run the two files one after the other, then the second one will throw an exception: - ReferenceError: Response is not defined, under Jest 0.10.2. However, under Jest 0.8.2, the tests passed.

NOTE The project is under Windows and due to some issues with the multi threading, we have to use jest --runInBand. I have made a small project to reproduce, but I only had the issues with that config.

Thanks, Pascale

audetpascale avatar Apr 22 '16 12:04 audetpascale

Here is the Gist...

audetpascale avatar Apr 22 '16 18:04 audetpascale

Would you mind re-trying this with Jest on master? I believe this bug was fixed recently.

cpojer avatar Apr 26 '16 07:04 cpojer

Ok, I tried out your gist and can confirm that jest -i passes the tests on Jest 12.

I had to add this:

"unmockedModulePathPatterns": [
  "node_modules/babel-polyfill"
]

to the Jest config however. There might be a minor bug there, individual from your issue and I will try to repro that :) Thank you for your patience!

cpojer avatar Apr 27 '16 08:04 cpojer

Oh yeah, that is indeed another bug I accidentally introduced. Fixed in #942 and will go out in 12.0.1. You won't need to add anything to the config then :)

cpojer avatar Apr 27 '16 08:04 cpojer

Hi Christoph, thanks for the responses. I will try in few days. For now, I am out the office ;) Have a good day!

audetpascale avatar Apr 27 '16 12:04 audetpascale

Everything is working. For history purpose, I had to change nothing, I did not add the babel-polyfill in the package.json and it is working.

audetpascale avatar Apr 28 '16 11:04 audetpascale

I'm having this issue on Jest 15.1.1, both new Response and new Request give ReferenceError: Response/Request is not defined.

Any recommendations?

edit: I solved it by importing isomorphic-fetch on my test file.

altaywtf avatar Sep 16 '16 20:09 altaywtf

We should re-open this issue. I am using version 23.6.0 and I am still getting this error. Is importing the isomorphic-fetch the only solution? Here is my devDependencies in package.json

"devDependencies": {
    "@vue/cli-plugin-babel": "3.0.3",
    "@vue/cli-plugin-e2e-cypress": "3.0.3",
    "@vue/cli-plugin-eslint": "3.0.3",
    "@vue/cli-plugin-unit-jest": "3.0.3",
    "@vue/cli-service": "3.0.3",
    "@vue/test-utils": "1.0.0-beta.25",
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "23.6.0",
    "less": "3.0.4",
    "less-loader": "4.1.0",
    "lodash": "4.17.10",
    "node-sass": "4.9.2",
    "sass-loader": "7.0.3",
    "vue-template-compiler": "2.5.16",
  }

kanteankit avatar Sep 20 '18 07:09 kanteankit

This issue is more than 2 years old. If you have a similar one, please open up a new issue with reproduction steps

SimenB avatar Sep 20 '18 08:09 SimenB

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

github-actions[bot] avatar May 12 '21 12:05 github-actions[bot]