Skip to content

Commit 61e3f1e

Browse files
committed
test: migrate to vitest
1 parent ea14740 commit 61e3f1e

7 files changed

Lines changed: 2666 additions & 524 deletions

File tree

graph.spec-d.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { describe, expectTypeOf, it } from 'vitest';
2+
import { Graph } from "./src/index.js";
3+
4+
/**
5+
* Those tests are not run. Their sole purpose is to test the types.
6+
*/
7+
describe('graph types', () => {
8+
it('should return the given node type', () => {
9+
const g = new Graph<string, { type: 'foo' | 'bar' }>();
10+
const props = g.nodes();
11+
12+
expectTypeOf(props).toEqualTypeOf<string[]>();
13+
});
14+
15+
it('should return the given edge properties type', () => {
16+
const g = new Graph<string, { type: 'foo' | 'bar' }>();
17+
const props = g.getEdgeProperties('a', 'b');
18+
19+
expectTypeOf(props).toEqualTypeOf<{ type: 'foo' | 'bar'}>();
20+
});
21+
22+
it('should only accept nodes of the given type', () => {
23+
const g = new Graph<{ id: string; label: string }>();
24+
g.addNode({ id: 'a', label: 'test' });
25+
26+
// @ts-expect-error Wrong node type
27+
g.addNode('a');
28+
});
29+
30+
it('should only accept properties of the given type', () => {
31+
const g = new Graph<string, { type: 'foo' | 'bar' }>();
32+
g.setEdgeProperties('a', 'b', { type: 'bar' });
33+
34+
// @ts-expect-error Wrong properties type
35+
g.setEdgeProperties('a', 'b', { type: 'nope' });
36+
})
37+
});

0 commit comments

Comments
 (0)