edge-runtime icon indicating copy to clipboard operation
edge-runtime copied to clipboard

jest-environment: extend `expect` with custom expectations

Open Schniz opened this issue 3 years ago • 0 comments

We can enable users to have simpler tests by having expectations that match the standard library we provide. For instance, Response matchers:

expect(response).toHaveStatusCode(...);

// These expectations can be shared with `Request` too:
expect(response.headers).toMatchHeaders({ ... });
await expect(response).toHaveJsonBody({ ... });
await expect(response).toHaveTextBody("...");

// or in a single line
await expect(response).toMatchResponse({
  status: ...,
  headers: { ... },
  text: "{ ... }",
  json: {}
});

// streams?
await expect(response.body).toEmitChunk(new Uint8Array([...]));

Schniz avatar Aug 04 '22 08:08 Schniz