Files
WRNexusJS/packages/test/test/mutation.test.ts
T
Clintchiz 53b9947ef9
Quality / quality (ubuntu-latest) (push) Failing after 9m51s
Quality / quality (windows-latest) (push) Canceled after 0s
fix: synchronize mounted component props
2026-08-23 19:42:39 +05:30

36 lines
1.3 KiB
TypeScript

import { expect, test } from "bun:test";
import { detectMutations } from "../src/mutation.ts";
test("detectMutations reports mutations whose behaviour changes", async () => {
const report = await detectMutations({
baseline: (amount: number) => amount,
mutations: [
{ name: "invert sign", value: (amount: number) => -amount },
{ name: "drop amount", value: () => 0 },
],
exercise: (adjust) => adjust(7),
});
expect(report.killed).toEqual(["invert sign", "drop amount"]);
expect(report.survived).toEqual([]);
});
test("detectMutations fails with the names of surviving mutations", async () => {
await expect(
detectMutations({
baseline: (amount: number) => amount,
mutations: [{ name: "wrong implementation", value: (amount: number) => amount }],
exercise: (adjust) => adjust(7),
}),
).rejects.toThrow(/WRN-MUTATION-SURVIVED: wrong implementation/);
});
test("detectMutations accepts structured observations through an equivalence function", async () => {
const report = await detectMutations({
baseline: { status: 200 },
mutations: [{ name: "deny request", value: { status: 403 } }],
exercise: async (response) => ({ ...response, volatile: crypto.randomUUID() }),
equivalent: (left, right) => left.status === right.status,
});
expect(report.killed).toEqual(["deny request"]);
});