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

Request.json() TypeError: Body is unusable when using jest.useFakeTimers in a test #2408

Open
4 tasks done
jhoward1994 opened this issue Jan 10, 2025 · 0 comments
Open
4 tasks done
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node

Comments

@jhoward1994
Copy link

jhoward1994 commented Jan 10, 2025

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 18 or higher

Node.js version

v20.15.1

Reproduction repository

https://github.com/strapi/strapi/tree/chore/upgrade-msw-v2

Reproduction steps

  • yarn; yarn run setup
  • yarn run test:front packages/core/content-manager/admin/src/pages/EditView/components/FormInputs/tests/UID.test.tsx

Please use branch chore/upgrade-msw-v2

Relevant code is:

Current behavior

Error parsing request body: TypeError: Body is unusable
  at log (admin/tests/server.ts:306:15)

I believe it is caused by the use of fake timers in https://github.com/strapi/strapi/blob/6d949f07f378849292a01ba9718634eecda65231/packages/core/content-manager/admin/src/pages/EditView/components/FormInputs/tests/UID.test.tsx#L143-L144

Expected behavior

We want to be able to extract the body of the request for the conditional logic here
https://github.com/strapi/strapi/blob/6d949f07f378849292a01ba9718634eecda65231/packages/core/content-manager/admin/tests/server.ts#L301-L313

I have tried using the jest fake timers with the doNotFake option as suggested here https://mswjs.io/docs/runbook/#:~:text=Requests%20are%20not%20resolving,%7D

As you can see by the PR here the overall goal is to upgrade Strapi to use msw v2

@jhoward1994 jhoward1994 added bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node labels Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node
Projects
None yet
Development

No branches or pull requests

1 participant