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