1
1
// make sure you import mocha-config before @angular/core
2
- import { assert } from './test-config' ;
3
- import { Component , ComponentRef , ElementRef , NgZone , Renderer2 , ViewChild } from '@angular/core' ;
4
- import { ProxyViewContainer } from 'ui/proxy-view-container' ;
5
- import { Red } from 'color/known-colors' ;
6
- import { dumpView } from './test-utils' ;
7
- import { LayoutBase } from 'ui/layouts/layout-base' ;
8
- import { StackLayout } from 'ui/layouts/stack-layout' ;
9
- import { ContentView } from 'ui/content-view' ;
10
- import { Button } from 'ui/button' ;
11
- import { registerElement } from 'nativescript-angular/element-registry' ;
12
- import * as button from 'tns-core-modules/ui/button' ;
13
- import * as view from 'tns-core-modules/ui/core/view' ;
14
- import { nTestBedAfterEach , nTestBedBeforeEach , nTestBedRender } from 'nativescript-angular/testing' ;
15
- import { ComponentFixture , TestBed } from '@angular/core/testing' ;
2
+ import { assert } from "./test-config" ;
3
+ import { Component , ComponentRef , ElementRef , NgZone , Renderer2 , ViewChild } from "@angular/core" ;
4
+ import { ProxyViewContainer } from "ui/proxy-view-container" ;
5
+ import { Red } from "color/known-colors" ;
6
+ import { dumpView } from "./test-utils" ;
7
+ import { LayoutBase } from "ui/layouts/layout-base" ;
8
+ import { StackLayout } from "ui/layouts/stack-layout" ;
9
+ import { ContentView } from "ui/content-view" ;
10
+ import { Button } from "ui/button" ;
11
+ import { registerElement } from "nativescript-angular/element-registry" ;
12
+ import * as button from "tns-core-modules/ui/button" ;
13
+ import * as view from "tns-core-modules/ui/core/view" ;
14
+ import { nTestBedAfterEach , nTestBedBeforeEach , nTestBedRender } from "nativescript-angular/testing" ;
15
+ import { ComponentFixture , TestBed } from "@angular/core/testing" ;
16
+ import { Observable } from "rxjs/Observable" ;
17
+ import { ReplaySubject } from "rxjs/ReplaySubject" ;
16
18
17
19
@Component ( {
18
20
template : `<StackLayout><Label text="Layout"></Label></StackLayout>`
@@ -226,10 +228,10 @@ export class NgControlSettersCount {
226
228
227
229
get buttons ( ) : ElementRef [ ] { return [ this . btn1 , this . btn2 , this . btn3 , this . btn4 ] ; }
228
230
229
- isAfterViewInit : boolean = false ;
231
+ ready$ : Observable < boolean > = new ReplaySubject < boolean > ( 1 ) ;
230
232
231
233
ngAfterViewInit ( ) {
232
- this . isAfterViewInit = true ;
234
+ ( this . ready$ as ReplaySubject < boolean > ) . next ( true ) ;
233
235
}
234
236
}
235
237
@@ -609,8 +611,7 @@ describe("Renderer attach/detach", () => {
609
611
} ) ;
610
612
} ) ;
611
613
612
- // TODO: I'm not sure about this lifecycle test.
613
- xdescribe ( "Renderer lifecycle" , ( ) => {
614
+ describe ( "Renderer lifecycle" , ( ) => {
614
615
let renderer : Renderer2 = null ;
615
616
beforeEach ( nTestBedBeforeEach ( [ ZonedRenderer , NgControlSettersCount ] ) ) ;
616
617
afterEach ( nTestBedAfterEach ( false ) ) ;
@@ -624,16 +625,28 @@ xdescribe("Renderer lifecycle", () => {
624
625
625
626
it ( "view native setters are called once on startup" , ( ) => {
626
627
const fixture = TestBed . createComponent ( NgControlSettersCount ) ;
627
- fixture . detectChanges ( ) ;
628
- const componentRef : ComponentRef < NgControlSettersCount > = fixture . componentRef ;
629
- assert . isTrue ( componentRef . instance . isAfterViewInit , "Expected the NgControlSettersCount to have passed its ngAfterViewInit." ) ;
630
- componentRef . instance . buttons . map ( btn => btn . nativeElement ) . forEach ( btn => {
631
- assert . isTrue ( btn . isLoaded , `Expected ${ btn . id } to be allready loaded.` ) ;
632
- assert . isFalse ( btn . isLayoutValid , `Expected ${ btn . id } 's layout to be invalid.` ) ;
633
-
634
- assert . equal ( btn . backgroundInternalSetNativeCount , 1 , `Expected ${ btn . id } backgroundInternalSetNativeCount to be called just once.` ) ;
635
- assert . equal ( btn . fontInternalSetNativeCount , 1 , `Expected ${ btn . id } fontInternalSetNativeCount to be called just once.` ) ;
636
- assert . equal ( btn . nativeBackgroundRedraws , 0 , `Expected ${ btn . id } nativeBackgroundRedraws to be called after its layout pass.` ) ;
628
+ const component : NgControlSettersCount = fixture . componentInstance ;
629
+ return component . ready$ . subscribe ( ( ) => {
630
+ component . buttons . map ( btn => btn . nativeElement ) . forEach ( btn => {
631
+ assert . isTrue ( btn . isLoaded , `Expected ${ btn . id } to be loaded.` ) ;
632
+ assert . isFalse (
633
+ btn . isLayoutValid ,
634
+ `Expected ${ btn . id } 's layout to be invalid because it is uninitialized.`
635
+ ) ;
636
+
637
+ assert . equal (
638
+ btn . backgroundInternalSetNativeCount , 1 ,
639
+ `Expected ${ btn . id } backgroundInternalSetNativeCount to be called just once.`
640
+ ) ;
641
+ assert . equal (
642
+ btn . fontInternalSetNativeCount , 1 ,
643
+ `Expected ${ btn . id } fontInternalSetNativeCount to be called just once.`
644
+ ) ;
645
+ assert . equal (
646
+ btn . nativeBackgroundRedraws , 0 ,
647
+ `Expected ${ btn . id } nativeBackgroundRedraws to be called after its layout pass.`
648
+ ) ;
649
+ } ) ;
637
650
} ) ;
638
651
} ) ;
639
652
} ) ;
0 commit comments