-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
34 lines (31 loc) · 1.13 KB
/
vitest.setup.ts
File metadata and controls
34 lines (31 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { expect } from "vitest";
expect.extend({
toYield<T>(received: Iterable<T>, expected: T[]) {
return this.equals(Array.from(received).sort(), expected.sort())
? {
message: () => `expected ${Array.from(received)} not to yield ${expected}`,
pass: true,
}
: {
message: () => `expected ${Array.from(received)} to yield ${expected}`,
pass: false,
};
},
toYieldOrdered<T>(received: Iterable<T>, expected: T[]) {
return this.equals(
isIterable(received) && typeof received !== "string" ? Array.from(received) : received,
expected,
)
? {
message: () => `expected ${Array.from(received)} not to yield ${expected}`,
pass: true,
}
: {
message: () => `expected ${Array.from(received)} to yield ${expected}`,
pass: false,
};
},
});
function isIterable<T>(obj: Iterable<T>) {
return obj != null && typeof obj[Symbol.iterator] === "function";
}