Skip to content

Commit 96e6070

Browse files
committed
test: Add new toBeClass matcher
1 parent a0ec42d commit 96e6070

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/setup.ts

+12
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ declare module 'bun:test' {
103103
interface Matchers {
104104
/** Asserts that a value is a plain `object`. */
105105
toBePlainObject(): void;
106+
/** Asserts that a value is a `class`. */
107+
toBeClass(): void;
106108
/** Asserts that a function has a specific number of parameters. */
107109
toHaveParameters(required: number, optional: number): void;
108110
}
@@ -119,6 +121,16 @@ expect.extend({
119121
};
120122
},
121123

124+
toBeClass(received: unknown) {
125+
return typeof received === 'function' &&
126+
/^class\s/.test(Function.prototype.toString.call(received))
127+
? { pass: true }
128+
: {
129+
pass: false,
130+
message: () => `expected ${String(received)} to be a class`,
131+
};
132+
},
133+
122134
toHaveParameters(received: unknown, required: number, optional: number) {
123135
if (typeof received !== 'function') {
124136
return {

0 commit comments

Comments
 (0)