playwright-msw icon indicating copy to clipboard operation
playwright-msw copied to clipboard

per-test mocking is broken as of MSW 1.3.0

Open AaronBuxbaum opened this issue 2 years ago • 0 comments

With msw @ 1.3.0, the following code works:

  test("request fails", async ({ page, worker }) => {
    await worker.use(
      graphql.query("MyQuery", (_, res, ctx) => res(ctx.status(500))),
    );
    await page.goto("/");
    await expect(page.getByText("I render!").first()).toBeVisible();
  });

where MyQuery is defined earlier:

const test = base.extend<TestFixtures>({
  worker: createWorkerFixture([graphql.query("MyQuery", (_, res, ctx) => res(ctx.json(...))))
});

However, updating 1.3.1 or onwards will cause the override to not be included. This is a pretty major problem, and very not obvious for those using this library! Hopefully we can fix it soon; happy to help if you point me to where changes are required.

Total guess: maybe the problem is caused by this change, a dependency of MSW? This bump was one of very few changes that occurred in MSW between these versions.

AaronBuxbaum avatar Oct 03 '23 21:10 AaronBuxbaum