@@ -44,92 +44,83 @@ describe('lazy loading', () => {
44
44
} ) ;
45
45
} ) ;
46
46
47
- it (
48
- 'should lazy load a module' ,
49
- async (
50
- inject ( [ UIRouter ] , ( router : UIRouter ) => {
51
- const { stateRegistry, stateService, globals } = router ;
52
- stateRegistry . register ( futureFoo ) ;
53
-
54
- const fixture = TestBed . createComponent ( UIView ) ;
55
- fixture . detectChanges ( ) ;
47
+ it ( 'should lazy load a module' , async (
48
+ inject ( [ UIRouter ] , ( router : UIRouter ) => {
49
+ const { stateRegistry, stateService, globals } = router ;
50
+ stateRegistry . register ( futureFoo ) ;
56
51
57
- let names = stateRegistry
58
- . get ( )
59
- . map ( state => state . name )
60
- . sort ( ) ;
61
- expect ( names . length ) . toBe ( 2 ) ;
62
- expect ( names ) . toEqual ( [ '' , 'foo.**' ] ) ;
63
-
64
- stateService . go ( 'foo' ) . then ( ( ) => {
65
- expect ( globals . current . name ) . toBe ( 'foo' ) ;
66
-
67
- names = stateRegistry
68
- . get ( )
69
- . map ( state => state . name )
70
- . sort ( ) ;
71
- expect ( names . length ) . toBe ( 4 ) ;
72
- expect ( names ) . toEqual ( [ '' , 'foo' , 'foo.child1' , 'foo.child2' ] ) ;
73
- } ) ;
74
- } ) ,
75
- ) ,
76
- ) ;
77
-
78
- it (
79
- 'should throw if no future state replacement is lazy loaded' ,
80
- async (
81
- inject ( [ UIRouter ] , ( router : UIRouter ) => {
82
- const { stateRegistry, stateService } = router ;
83
- stateService . defaultErrorHandler ( ( ) => null ) ;
84
- stateRegistry . register ( futureBar ) ;
85
-
86
- const fixture = TestBed . createComponent ( UIView ) ;
87
- fixture . detectChanges ( ) ;
52
+ const fixture = TestBed . createComponent ( UIView ) ;
53
+ fixture . detectChanges ( ) ;
88
54
89
- const names = stateRegistry
90
- . get ( )
91
- . map ( state => state . name )
92
- . sort ( ) ;
93
- expect ( names . length ) . toBe ( 2 ) ;
94
- expect ( names ) . toEqual ( [ '' , 'bar.**' ] ) ;
95
-
96
- const success = ( ) => {
97
- throw Error ( 'success not expected' ) ;
98
- } ;
99
- const error = err => {
100
- expect ( err . detail . message ) . toContain ( "The lazy loaded NgModule must have a state named 'bar'" ) ;
101
- } ;
102
- stateService . go ( 'bar' ) . then ( success , error ) ;
103
- } ) ,
104
- ) ,
105
- ) ;
106
-
107
- it (
108
- 'should support loadChildren on non-future state (manual state cleanup)' ,
109
- async (
110
- inject ( [ UIRouter ] , ( router : UIRouter ) => {
111
- const { stateRegistry, stateService } = router ;
112
- stateRegistry . register ( augment1 ) ;
113
- stateRegistry . register ( augment2 ) ;
114
-
115
- const fixture = TestBed . createComponent ( UIView ) ;
116
- fixture . detectChanges ( ) ;
55
+ let names = stateRegistry
56
+ . get ( )
57
+ . map ( state => state . name )
58
+ . sort ( ) ;
59
+ expect ( names . length ) . toBe ( 2 ) ;
60
+ expect ( names ) . toEqual ( [ '' , 'foo.**' ] ) ;
117
61
118
- const names = stateRegistry
62
+ stateService . go ( 'foo' ) . then ( ( ) => {
63
+ expect ( globals . current . name ) . toBe ( 'foo' ) ;
64
+
65
+ names = stateRegistry
119
66
. get ( )
120
67
. map ( state => state . name )
121
68
. sort ( ) ;
122
- expect ( names ) . toEqual ( [ '' , 'augment1' , 'augment1.augment2' ] ) ;
123
-
124
- const wait = delay => new Promise ( resolve => setTimeout ( resolve , delay ) ) ;
125
- stateService . go ( 'augment1.augment2' ) . then ( ( ) => {
126
- fixture . detectChanges ( ) ;
127
- expect ( stateService . current . name ) . toBe ( 'augment1.augment2' ) ;
128
- expect ( fixture . debugElement . nativeElement . textContent . replace ( / \s + / g, ' ' ) . trim ( ) ) . toBe (
129
- 'Component 1 Component 2' ,
130
- ) ;
131
- } ) ;
132
- } ) ,
133
- ) ,
134
- ) ;
69
+ expect ( names . length ) . toBe ( 4 ) ;
70
+ expect ( names ) . toEqual ( [ '' , 'foo' , 'foo.child1' , 'foo.child2' ] ) ;
71
+ } ) ;
72
+ } )
73
+ ) ) ;
74
+
75
+ it ( 'should throw if no future state replacement is lazy loaded' , async (
76
+ inject ( [ UIRouter ] , ( router : UIRouter ) => {
77
+ const { stateRegistry, stateService } = router ;
78
+ stateService . defaultErrorHandler ( ( ) => null ) ;
79
+ stateRegistry . register ( futureBar ) ;
80
+
81
+ const fixture = TestBed . createComponent ( UIView ) ;
82
+ fixture . detectChanges ( ) ;
83
+
84
+ const names = stateRegistry
85
+ . get ( )
86
+ . map ( state => state . name )
87
+ . sort ( ) ;
88
+ expect ( names . length ) . toBe ( 2 ) ;
89
+ expect ( names ) . toEqual ( [ '' , 'bar.**' ] ) ;
90
+
91
+ const success = ( ) => {
92
+ throw Error ( 'success not expected' ) ;
93
+ } ;
94
+ const error = err => {
95
+ expect ( err . detail . message ) . toContain ( "The lazy loaded NgModule must have a state named 'bar'" ) ;
96
+ } ;
97
+ stateService . go ( 'bar' ) . then ( success , error ) ;
98
+ } )
99
+ ) ) ;
100
+
101
+ it ( 'should support loadChildren on non-future state (manual state cleanup)' , async (
102
+ inject ( [ UIRouter ] , ( router : UIRouter ) => {
103
+ const { stateRegistry, stateService } = router ;
104
+ stateRegistry . register ( augment1 ) ;
105
+ stateRegistry . register ( augment2 ) ;
106
+
107
+ const fixture = TestBed . createComponent ( UIView ) ;
108
+ fixture . detectChanges ( ) ;
109
+
110
+ const names = stateRegistry
111
+ . get ( )
112
+ . map ( state => state . name )
113
+ . sort ( ) ;
114
+ expect ( names ) . toEqual ( [ '' , 'augment1' , 'augment1.augment2' ] ) ;
115
+
116
+ const wait = delay => new Promise ( resolve => setTimeout ( resolve , delay ) ) ;
117
+ stateService . go ( 'augment1.augment2' ) . then ( ( ) => {
118
+ fixture . detectChanges ( ) ;
119
+ expect ( stateService . current . name ) . toBe ( 'augment1.augment2' ) ;
120
+ expect ( fixture . debugElement . nativeElement . textContent . replace ( / \s + / g, ' ' ) . trim ( ) ) . toBe (
121
+ 'Component 1 Component 2'
122
+ ) ;
123
+ } ) ;
124
+ } )
125
+ ) ) ;
135
126
} ) ;
0 commit comments