-
-
Notifications
You must be signed in to change notification settings - Fork 537
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
MSW randomly fails to mock GET request while running tests with karma / jasmine #854
Comments
Hey, @DennisOosterling. Please update to Please, could you put this into a reproduction repository for me to look at? I'm happy to look into this, but I don't have the capacity to set up example repositories. I hope for your understanding. |
Hi @kettanaito reproduction repository was mentioned under the header Thank you for the |
I'm sorry for overlooking this, @DennisOosterling 🤦🏻. Thank you for preparing the repo! |
In my case, I though I was running into this issue. However what it turned to be was that the mockServiceWorker.js static dependency was not being properly loaded into the environment and worker.start would never finish resolving because it got a 404 error when loading. |
I'm fairly certain I'm having this issue with testem + Chrome 96 (headless) and msw @kettanaito is there any debugging I could help with to better understand the issue? As mentioned here and in the other issue this happens randomly and only in the first test that uses msw. Update: forgot to include the test code! import { rest, setupWorker } from 'msw';
import { module, test } from 'qunit';
module('Acceptance | REST', function () {
test('mocking a REST API', async function (assert) {
let worker = setupWorker();
await worker.start({
onUnhandledRequest: 'error',
});
worker.use(
rest.get('/people', (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
people: [
{
name: 'Jane Doe',
email: '[email protected]',
},
],
})
);
})
);
// Test always passes if this is uncommented:
// await new Promise((resolve) => setTimeout(resolve, 50));
let response = await fetch('/people');
assert.equal(response.status, 200);
worker.resetHandlers();
});
}); Update 2: No failures when using headless Firefox instead of Chrome. |
An update on this: we've recently solved an issue where the If they still don't, please attach a reproduction repository for me to look at. Thanks. |
Environment
Request handlers
handlers.ts
browser.ts
test.ts
Actual request
fake-service.service.spec.ts
fake-service.service.ts
Current behavior
Currently, while running tests with karma in a fresh angular project, the tests will randomly fail with a message coming from msw that it
Failed to mock GET request
as shown in the screenshots below. I haven't found a way to reproduce this problem as it really seems to happen randomly (sometimes within 5 min, sometimes 10-15min of retrying). This happens both locally as in the CI.Example repo can be found here
Expected behavior
msw will be able to mock the request
Screenshots
The text was updated successfully, but these errors were encountered: