-
-
Notifications
You must be signed in to change notification settings - Fork 880
/
vitest-extensions.ts
33 lines (28 loc) · 960 Bytes
/
vitest-extensions.ts
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
import { expect } from 'vitest';
expect.extend({
toContainDuplicates<T>(received: T[]) {
const { isNot } = this;
const uniques = new Set(received);
const duplications = received.filter((entry) => !uniques.delete(entry));
const uniqueDuplication = [...new Set(duplications)];
return {
pass: uniqueDuplication.length !== 0,
message: () =>
isNot
? `Duplicated values are [${uniqueDuplication.join(', ')}]`
: `No duplicate values in [${received.join(', ')}]`,
};
},
});
interface CustomMatchers {
toContainDuplicates(): void;
}
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Vi {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface Assertion extends CustomMatchers {}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface AsymmetricMatchersContaining extends CustomMatchers {}
}
}