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') is always null #1992

Closed
kettanaito opened this issue Jan 24, 2024 Discussed in #1991 · 3 comments · Fixed by #1993
Closed

"request" in worker.events.on('response:mocked') is always null #1992

kettanaito opened this issue Jan 24, 2024 Discussed in #1991 · 3 comments · Fixed by #1993
Assignees
Labels
bug Something isn't working good first issue Good for newcomers scope:browser Related to MSW running in a browser

Comments

@kettanaito
Copy link
Member

Discussed in #1991

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 kettanaito added scope:browser Related to MSW running in a browser bug Something isn't working good first issue Good for newcomers labels Jan 24, 2024
@kettanaito
Copy link
Member Author

I'd start here:

/**
* @todo @fixme In this context, we don't know anything about
* the request.
*/
request: null as any,

And figure out why we don't know anything about the request.

@kettanaito
Copy link
Member Author

Opened a fix at #1993

@kettanaito
Copy link
Member Author

Released: v2.1.5 🎉

This has been released in v2.1.5!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working good first issue Good for newcomers scope:browser Related to MSW running in a browser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant