-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvitest.setup.ts
32 lines (29 loc) · 875 Bytes
/
vitest.setup.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
import Graphology from 'graphology';
import { Colorable } from './src/color.js';
import { expect } from 'vitest';
expect.extend({
toBeColored: (graph: Graphology.UndirectedGraph<Colorable>) => {
for (const edge of graph.edgeEntries()) {
const [a, b] = [edge.source, edge.target].map((node) => ({
key: node,
color: graph.getNodeAttributes(node).color
}));
[a, b].forEach((node) => {
if (a.color === undefined) {
return {
pass: false,
message: () => `expected node '${node.key}' be colored`
};
}
});
if (a.color === b.color) {
return {
pass: false,
message: () =>
`expected nodes '${a.key}' and '${b.key}' to be colored with different colors`
};
}
}
return { pass: true, message: () => '' };
}
});