Skip to content

Unable to use with msw to mock requests #775

@rinux55

Description

@rinux55

Environment


  • Operating System: Darwin
  • Node Version: v18.19.1
  • Nuxt Version: 3.10.3
  • CLI Version: 3.10.1
  • Nitro Version: 2.9.3
  • Package Manager: [email protected]
  • Builder: -
  • User Config: devtools
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/~/github.com/rinux55/nuxt-fetch

See app.test.ts. In the test/setup.ts and test/server.ts there is an msw server being set up with a mocked endpoint.

Describe the bug

To mock requests made using $fetch and useFetch, I expect to be able to use a utility like msw.

Unfortunately, this doesn't seem to work in combination with @nuxt/test-utils.

I've created a reproduction where you can see that globalThis.fetch is mocked just fine, but useFetch or fetch is not:

https://stackblitz.com/~/github.com/rinux55/nuxt-fetch

Any help with this would be greatly appreciated.

Additional context

No response

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions