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 in worker.events.on('response:mocked', {request} is always null #2014

Closed
canrozanes opened this issue Feb 5, 2024 Discussed in #1991 · 5 comments
Closed

Request in worker.events.on('response:mocked', {request} is always null #2014

canrozanes opened this issue Feb 5, 2024 Discussed in #1991 · 5 comments

Comments

@canrozanes
Copy link

Discussed in #1991

Just converting it to an issue so that it can be tracked.

Originally posted by canrozanes January 22, 2024
Hi,

I was following the docs on life-cycle events and I was trying to assert on a response after making an API call.

I have the following piece of code that saves all the requests so that I can assert on the responses later.

// QUnit  setup
hooks.beforeEach(async function (this: TestContextWithMsw) {
    this.worker = setupWorker(...handlers);
    this.worker.events.on('response:mocked', ({ request, requestId, response }) => {
      this.handledRequests.push({ request, requestId, response });
    });
});

I can clearly see that MSW sends a response in the browser network tab but when I add a debugger inside the 'response:mocked' callback, I see that all the request are null.

Screenshot 2024-01-22 at 10 39 35 AM

What could I be missing?

@kettanaito
Copy link
Member

Hi, @canrozanes. I've already tackled this issue in #1992. Please update MSW to get the fix:

npm i msw@latest

Released in v2.1.5 (Release notes). Thanks.

@canrozanes
Copy link
Author

Hey @kettanaito sorry for the duplicate. Thanks for the fix.

Also, is there a reason url is not properly populated in the response object?

@kettanaito
Copy link
Member

@canrozanes, do you mean the response instance you get from the life-cycle event listener doesn't have the correct response.url set?

@canrozanes
Copy link
Author

@kettanaito yes exactly! response.url is ''

@kettanaito
Copy link
Member

Got it! Tracking in #2030, fixing in #2031. Thanks!

@github-actions github-actions bot locked and limited conversation to collaborators Oct 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants