1
1
// make sure you import mocha-config before @angular/core
2
- import { ChangeDetectionStrategy , Component , ViewChild } from ' @angular/core' ;
3
- import { DetachedLoader } from ' nativescript-angular/common/detached-loader' ;
4
- import { nTestBedAfterEach , nTestBedBeforeEach , nTestBedRender } from ' nativescript-angular/testing' ;
2
+ import { ChangeDetectionStrategy , Component , ViewChild } from " @angular/core" ;
3
+ import { DetachedLoader } from " nativescript-angular" ;
4
+ import { nTestBedAfterEach , nTestBedBeforeEach , nTestBedRender } from " nativescript-angular/testing" ;
5
5
6
6
@Component ( {
7
7
template : `<StackLayout><Label text="COMPONENT"></Label></StackLayout>`
@@ -11,18 +11,6 @@ class TestComponent { }
11
11
12
12
class LoaderComponentBase {
13
13
@ViewChild ( DetachedLoader ) public loader : DetachedLoader ;
14
-
15
- public ready : Promise < LoaderComponentBase > ;
16
- private resolve ;
17
- constructor ( ) {
18
- this . ready = new Promise ( ( reslove , reject ) => {
19
- this . resolve = reslove ;
20
- } ) ;
21
- }
22
- ngAfterViewInit ( ) {
23
- console . log ( "!!! ngAfterViewInit -> loader: " + this . loader ) ;
24
- this . resolve ( this ) ;
25
- }
26
14
}
27
15
28
16
@Component ( {
@@ -46,35 +34,23 @@ export class LoaderComponent extends LoaderComponentBase {}
46
34
} )
47
35
export class LoaderComponentOnPush extends LoaderComponentBase { }
48
36
49
- // TODO(JD): These tests should work, but demonstrate an annoying bug I've noticed sometimes with @ViewChild
50
- //
51
- // The @ViewChild (DetachedLoader) on LoaderComponentBase fails. Can anyone shed some light on why?
52
- xdescribe ( "DetachedLoader" , ( ) => {
37
+ describe ( "DetachedLoader" , ( ) => {
53
38
54
39
beforeEach ( nTestBedBeforeEach ( [ LoaderComponent , LoaderComponentOnPush ] , [ ] , [ ] , [ TestComponent ] ) ) ;
55
40
afterEach ( nTestBedAfterEach ( ) ) ;
56
41
57
- it ( "creates component" , ( done ) => {
58
- let component : LoaderComponent ;
59
-
60
- nTestBedRender ( LoaderComponent )
61
- . then ( ( fixture ) => {
62
- component = fixture . componentRef . instance ;
63
- return component . ready ;
64
- } )
65
- . then ( ( ) => component . loader . loadComponent ( TestComponent ) )
66
- . then ( ( ) => done ( ) )
67
- . catch ( done ) ;
42
+ it ( "creates component" , ( ) => {
43
+ return nTestBedRender ( LoaderComponent ) . then ( ( fixture ) => {
44
+ const component : LoaderComponent = fixture . componentRef . instance ;
45
+ return component . loader . loadComponent ( TestComponent ) ;
46
+ } ) ;
68
47
} ) ;
69
48
70
49
71
- it ( "creates component when ChangeDetectionStrategy is OnPush" , ( done ) => {
72
- nTestBedRender ( LoaderComponentOnPush )
73
- . then ( ( fixture ) => {
74
- const component : LoaderComponent = fixture . componentRef . instance ;
75
- return component . loader . loadComponent ( TestComponent ) ;
76
- } )
77
- . then ( ( ) => done ( ) )
78
- . catch ( done ) ;
50
+ it ( "creates component when ChangeDetectionStrategy is OnPush" , ( ) => {
51
+ return nTestBedRender ( LoaderComponentOnPush ) . then ( ( fixture ) => {
52
+ const component : LoaderComponentOnPush = fixture . componentRef . instance ;
53
+ return component . loader . loadComponent ( TestComponent ) ;
54
+ } ) ;
79
55
} ) ;
80
56
} ) ;
0 commit comments