Skip to content

Right-hand side of 'instanceof' is not an object with jsdom #884

@jdelStrother

Description

@jdelStrother

Thanks for fetch-mock!

I've been trying to upgrade fetch-mock-jest -> @fetch-mock/jest, but had some issues with our tests that use jsdom, where Request/Response etc aren't defined on globalThis. I suspect it's the same issue as #864

I created an example repo at https://github.com/jdelStrother/fetch-mock-jest

$ npm test

> [email protected] test
> jest --all

 PASS  ./mock-old.test.js
 FAIL  ./mock.test.js
  ● can fetch stuff

    TypeError: Right-hand side of 'instanceof' is not an object

       8 |
       9 | it("can fetch stuff", async () => {
    > 10 |   let r = await fetch("http://example.com");
         |                 ^
      11 |   expect(r.status).toEqual(418);
      12 | });
      13 |

      at FetchMockJest._callee$ (node_modules/fetch-mock/dist/esm/FetchMock.js:56:25)
      at fetch (mock.test.js:10:17)
      at call (mock.test.js:2:1)
      at Generator.tryCatch (mock.test.js:2:1)
      at Generator._invoke [as next] (mock.test.js:2:1)
      at asyncGeneratorStep (mock.test.js:2:1)
      at asyncGeneratorStep (mock.test.js:2:1)
      at _next (mock.test.js:2:1)
      at Object.<anonymous> (mock.test.js:2:1)

Test Suites: 1 failed, 1 passed, 2 total
Tests:       1 failed, 1 passed, 2 total
Snapshots:   0 total
Time:        1.178 s
Ran all test suites.

The first error comes from

if (requestInput instanceof this.config.Request) {
, but if I naively bypass that check there seem to be a rabbithole of further errors (Response is not defined, ReadableStream is not defined ...)

I'm not sure if jsdom is something you want to support, but thought it was worth highlighting as something that used to work under fetch-mock-jest

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions