1
1
import { instance as globalContainer } from "../dependency-container" ;
2
2
import { inject , injectable } from "../decorators" ;
3
-
3
+ import { A01 } from "./fixtures/01-test-case-A01-injects-B01" ;
4
+ import errorMatch from "./utils/error-match" ;
4
5
afterEach ( ( ) => {
5
6
globalContainer . reset ( ) ;
6
7
} ) ;
@@ -26,16 +27,12 @@ test("Error message composition", () => {
26
27
expect ( ( ) => {
27
28
globalContainer . resolve ( A ) ;
28
29
} ) . toThrow (
29
- new RegExp (
30
- [
31
- / C a n n o t i n j e c t t h e d e p e n d e n c y " b " a t p o s i t i o n # 1 o f " A " c o n s t r u c t o r \. R e a s o n : / ,
32
- / C a n n o t i n j e c t t h e d e p e n d e n c y " c " a t p o s i t i o n # 0 o f " B " c o n s t r u c t o r \. R e a s o n : / ,
33
- / C a n n o t i n j e c t t h e d e p e n d e n c y " s " a t p o s i t i o n # 0 o f " C " c o n s t r u c t o r \. R e a s o n : / ,
34
- / T y p e I n f o n o t k n o w n f o r " O b j e c t " /
35
- ]
36
- . map ( x => x . source )
37
- . join ( "\\s+" )
38
- )
30
+ errorMatch ( [
31
+ / C a n n o t i n j e c t t h e d e p e n d e n c y " b " a t p o s i t i o n # 1 o f " A " c o n s t r u c t o r \. R e a s o n : / ,
32
+ / C a n n o t i n j e c t t h e d e p e n d e n c y " c " a t p o s i t i o n # 0 o f " B " c o n s t r u c t o r \. R e a s o n : / ,
33
+ / C a n n o t i n j e c t t h e d e p e n d e n c y " s " a t p o s i t i o n # 0 o f " C " c o n s t r u c t o r \. R e a s o n : / ,
34
+ / T y p e I n f o n o t k n o w n f o r " O b j e c t " /
35
+ ] )
39
36
) ;
40
37
} ) ;
41
38
@@ -48,13 +45,21 @@ test("Param position", () => {
48
45
expect ( ( ) => {
49
46
globalContainer . resolve ( A ) ;
50
47
} ) . toThrow (
51
- new RegExp (
52
- [
53
- / C a n n o t i n j e c t t h e d e p e n d e n c y " j " a t p o s i t i o n # 0 o f " A " c o n s t r u c t o r \. R e a s o n : / ,
54
- / A t t e m p t e d t o r e s o l v e u n r e g i s t e r e d d e p e n d e n c y t o k e n : " m i s s i n g " /
55
- ]
56
- . map ( x => x . source )
57
- . join ( "\\s+" )
58
- )
48
+ errorMatch ( [
49
+ / C a n n o t i n j e c t t h e d e p e n d e n c y " j " a t p o s i t i o n # 0 o f " A " c o n s t r u c t o r \. R e a s o n : / ,
50
+ / A t t e m p t e d t o r e s o l v e u n r e g i s t e r e d d e p e n d e n c y t o k e n : " m i s s i n g " /
51
+ ] )
52
+ ) ;
53
+ } ) ;
54
+
55
+ test ( "Detect circular dependency" , ( ) => {
56
+ expect ( ( ) => {
57
+ globalContainer . resolve ( A01 ) ;
58
+ } ) . toThrow (
59
+ errorMatch ( [
60
+ / C a n n o t i n j e c t t h e d e p e n d e n c y " b " a t p o s i t i o n # 0 o f " A 0 1 " c o n s t r u c t o r \. R e a s o n : / ,
61
+ / C a n n o t i n j e c t t h e d e p e n d e n c y " a " a t p o s i t i o n # 0 o f " B 0 1 " c o n s t r u c t o r \. R e a s o n : / ,
62
+ / A t t e m p t e d t o c o n s t r u c t a n u n d e f i n e d c o n s t r u c t o r . C o u l d m e a n a c i r c u l a r d e p e n d e n c y p r o b l e m ./
63
+ ] )
59
64
) ;
60
65
} ) ;
0 commit comments