valendres / playwright-msw

A Mock Service Worker API for Playwright

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

per-test mocking is broken as of MSW 1.3.0

AaronBuxbaum opened this issue · 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.