edge-runtime
edge-runtime copied to clipboard
jest-environment: extend `expect` with custom expectations
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([...]));