Skip to content

Commit

Permalink
Basic implementation
Browse files Browse the repository at this point in the history
Everything seems to be fine...
  • Loading branch information
dosolkowski-work committed Oct 24, 2024
1 parent cae9372 commit 8aef5b6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/example-vitest.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import "vitest";

interface CustomMatchers {
toBeFrob: () => void;
}

declare module "vitest" {
interface Assertion<T = any> extends CustomMatchers {}
interface AsymmetricMatchersContaining extends CustomMatchers {}
}
8 changes: 6 additions & 2 deletions src/example.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
test("example", () => {
test("baseline", () => {
expect(1 + 1).toBe(2);
})
});

test("toBeFrob", () => {
expect("frob").toBeFrob();
});
19 changes: 19 additions & 0 deletions src/setupTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
expect.extend({
toBeFrob(actual) {
if (typeof actual !== "string") {
throw new Error("Actual value must be a string");
}

const { utils, isNot } = this;

let pass = actual === "frob";
if (isNot) {
pass = !pass;
}

return {
pass,
message: () => `expected ${utils.printReceived(actual)} to be ${utils.printExpected("frob")}`
};
},
});

0 comments on commit 8aef5b6

Please sign in to comment.