Skip to content

Commit 3c82897

Browse files
author
vakrilov
committed
chore(tests): Unit tests made green again
1 parent 1ad6486 commit 3c82897

File tree

6 files changed

+52
-62
lines changed

6 files changed

+52
-62
lines changed

Diff for: nativescript-angular/platform-common.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ export class NativeScriptSanitizer extends Sanitizer {
6767
}
6868

6969
// Add a fake polyfill for the document object
70-
(<any>global).document = (<any>global).document || {};
70+
(<any>global).document = (<any>global).document || {
71+
getElementById: () => { return undefined; }
72+
};
73+
7174
const doc = (<any>global).document;
7275
doc.body = Object.assign(doc.body || {}, {
7376
isOverride: true,

Diff for: nativescript-angular/testing/src/util.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ export function nsTestBedAfterEach(resetEnv = true, resetFn = nsTestBedInit) {
125125
const root = testingRootView() as LayoutBase;
126126
const fixtures = activeTestFixtures.pop();
127127
fixtures.forEach((fixture) => {
128-
root.removeChild(fixture.nativeElement);
128+
const fixtureView = <View>fixture.nativeElement;
129+
if (fixtureView.parent === root) {
130+
root.removeChild(fixtureView);
131+
}
129132
fixture.destroy();
130133
});
131134
TestBed.resetTestingModule();
@@ -144,10 +147,10 @@ export function nsTestBedRender<T>(componentType: Type<T>): Promise<ComponentFix
144147
const fixture = TestBed.createComponent(componentType);
145148
fixture.detectChanges();
146149
return fixture.whenRenderingDone()
147-
// TODO(jd): it seems that the whenStable and whenRenderingDone utilities of ComponentFixture
148-
// do not work as expected. I looked at how to fix it and it's not clear how to provide
149-
// a {N} specific subclass, because ComponentFixture is newed directly rather than injected
150-
// What to do about it? Maybe fakeAsync can help? For now just setTimeout for 100ms (x_X)
150+
// TODO(jd): it seems that the whenStable and whenRenderingDone utilities of ComponentFixture
151+
// do not work as expected. I looked at how to fix it and it's not clear how to provide
152+
// a {N} specific subclass, because ComponentFixture is newed directly rather than injected
153+
// What to do about it? Maybe fakeAsync can help? For now just setTimeout for 100ms (x_X)
151154
.then(promiseWait(100))
152155
.then(() => {
153156
const list = activeTestFixtures[activeTestFixtures.length - 1];

Diff for: tests/app/tests/platform-filter-components.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe("Platform filter directives", () => {
4747
return nsTestBedRender(IosSpecificComponent).then((fixture) => {
4848
const componentRef = fixture.componentRef;
4949
const componentRoot = componentRef.instance.elementRef.nativeElement;
50-
assert.isTrue(dumpView(componentRoot, true).indexOf("(Label[text=IOS])") >= 0);
50+
assert.isTrue(dumpView(componentRoot, true).indexOf("(label[text=IOS])") >= 0);
5151
});
5252
});
5353
it("does not render android specific content", () => {
@@ -62,7 +62,7 @@ describe("Platform filter directives", () => {
6262
const componentRef = fixture.componentRef;
6363
const componentRoot = componentRef.instance.elementRef.nativeElement;
6464
assert.equal(
65-
"(ProxyViewContainer (StackLayout (Label[text=IOS])))",
65+
"(proxyviewcontainer (stacklayout (label[text=IOS])))",
6666
dumpView(componentRoot, true));
6767
});
6868
});
@@ -79,7 +79,7 @@ describe("Platform filter directives", () => {
7979
return nsTestBedRender(AndroidSpecificComponent).then((fixture) => {
8080
const componentRef = fixture.componentRef;
8181
const componentRoot = componentRef.instance.elementRef.nativeElement;
82-
assert.isTrue(dumpView(componentRoot, true).indexOf("(Label[text=ANDROID])") >= 0);
82+
assert.isTrue(dumpView(componentRoot, true).indexOf("(label[text=ANDROID])") >= 0);
8383
});
8484
});
8585
it("does not render ios specific content", () => {
@@ -94,7 +94,7 @@ describe("Platform filter directives", () => {
9494
const componentRef = fixture.componentRef;
9595
const componentRoot = componentRef.instance.elementRef.nativeElement;
9696
assert.equal(
97-
"(ProxyViewContainer (StackLayout (Label[text=ANDROID])))",
97+
"(proxyviewcontainer (stacklayout (label[text=ANDROID])))",
9898
dumpView(componentRoot, true));
9999
});
100100
});

Diff for: tests/app/tests/renderer-tests.ts

+29-29
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,15 @@ describe("Renderer E2E", () => {
262262
return nsTestBedRender(LayoutWithLabel).then((fixture) => {
263263
const componentRef: ComponentRef<LayoutWithLabel> = fixture.componentRef;
264264
const componentRoot = componentRef.instance.elementRef.nativeElement;
265-
assert.equal("(ProxyViewContainer (StackLayout (Label)))", dumpView(componentRoot));
265+
assert.equal("(proxyviewcontainer (stacklayout (label)))", dumpView(componentRoot));
266266
});
267267
});
268268

269269
it("component without a layout", () => {
270270
return nsTestBedRender(LabelContainer).then((fixture) => {
271271
const componentRef: ComponentRef<LabelContainer> = fixture.componentRef;
272272
const componentRoot = componentRef.instance.elementRef.nativeElement;
273-
assert.equal("(ProxyViewContainer (GridLayout (ProxyViewContainer (Label))))", dumpView(componentRoot));
273+
assert.equal("(proxyviewcontainer (gridlayout (proxyviewcontainer (label))))", dumpView(componentRoot));
274274
});
275275
});
276276

@@ -279,7 +279,7 @@ describe("Renderer E2E", () => {
279279
const componentRef: ComponentRef<ProjectionContainer> = fixture.componentRef;
280280
const componentRoot = componentRef.instance.elementRef.nativeElement;
281281
assert.equal(
282-
"(ProxyViewContainer (GridLayout (ProxyViewContainer (StackLayout (Button)))))",
282+
"(proxyviewcontainer (gridlayout (proxyviewcontainer (stacklayout (button)))))",
283283
dumpView(componentRoot));
284284
});
285285
});
@@ -355,7 +355,7 @@ describe("Renderer E2E", () => {
355355
return nsTestBedRender(NgIfLabel).then((fixture) => {
356356
const componentRef: ComponentRef<NgIfLabel> = fixture.componentRef;
357357
const componentRoot = componentRef.instance.elementRef.nativeElement;
358-
assert.equal("(ProxyViewContainer)", dumpView(componentRoot));
358+
assert.equal("(proxyviewcontainer)", dumpView(componentRoot));
359359
});
360360
});
361361

@@ -367,7 +367,7 @@ describe("Renderer E2E", () => {
367367

368368
component.show = true;
369369
fixture.detectChanges();
370-
assert.equal("(ProxyViewContainer (Label))", dumpView(componentRoot));
370+
assert.equal("(proxyviewcontainer (label))", dumpView(componentRoot));
371371
});
372372
});
373373

@@ -380,7 +380,7 @@ describe("Renderer E2E", () => {
380380
component.show = true;
381381
fixture.detectChanges();
382382
assert.equal(
383-
"(ProxyViewContainer (StackLayout (Label), (Button)))",
383+
"(proxyviewcontainer (stacklayout (label), (button)))",
384384
dumpView(componentRoot));
385385
});
386386
});
@@ -394,13 +394,13 @@ describe("Renderer E2E", () => {
394394
component.show = true;
395395
fixture.detectChanges();
396396
assert.equal(
397-
"(ProxyViewContainer " +
398-
"(StackLayout " +
399-
"(Label[text=1]), " +
400-
"(Label[text=2]), " +
401-
"(Label[text=3]), " +
402-
"(Label[text=4]), " + // the content to be conditionally displayed
403-
"(Label[text=5])" +
397+
"(proxyviewcontainer " +
398+
"(stacklayout " +
399+
"(label[text=1]), " +
400+
"(label[text=2]), " +
401+
"(label[text=3]), " +
402+
"(label[text=4]), " + // the content to be conditionally displayed
403+
"(label[text=5])" +
404404
")" +
405405
")",
406406
dumpView(componentRoot, true));
@@ -416,9 +416,9 @@ describe("Renderer E2E", () => {
416416
fixture.detectChanges();
417417

418418
assert.equal(
419-
"(ProxyViewContainer " +
420-
"(StackLayout " +
421-
"(Label[text=If])" +
419+
"(proxyviewcontainer " +
420+
"(stacklayout " +
421+
"(label[text=If])" +
422422
")" +
423423
")",
424424

@@ -435,9 +435,9 @@ describe("Renderer E2E", () => {
435435
component.show = false;
436436
fixture.detectChanges();
437437
assert.equal(
438-
"(ProxyViewContainer " +
439-
"(StackLayout " +
440-
"(Label[text=Else])" +
438+
"(proxyviewcontainer " +
439+
"(stacklayout " +
440+
"(label[text=Else])" +
441441
")" +
442442
")",
443443

@@ -453,9 +453,9 @@ describe("Renderer E2E", () => {
453453

454454
fixture.detectChanges();
455455
assert.equal(
456-
"(ProxyViewContainer " +
457-
"(StackLayout " +
458-
"(Label[text=Then])" +
456+
"(proxyviewcontainer " +
457+
"(stacklayout " +
458+
"(label[text=Then])" +
459459
")" +
460460
")",
461461

@@ -473,9 +473,9 @@ describe("Renderer E2E", () => {
473473
component.show = false;
474474
fixture.detectChanges();
475475
assert.equal(
476-
"(ProxyViewContainer " +
477-
"(StackLayout " +
478-
"(Label[text=Else])" +
476+
"(proxyviewcontainer " +
477+
"(stacklayout " +
478+
"(label[text=Else])" +
479479
")" +
480480
")",
481481

@@ -488,7 +488,7 @@ describe("Renderer E2E", () => {
488488
const componentRef: ComponentRef<NgForLabel> = fixture.componentRef;
489489
const componentRoot = componentRef.instance.elementRef.nativeElement;
490490
assert.equal(
491-
"(ProxyViewContainer (Label[text=one]), (Label[text=two]), (Label[text=three]))",
491+
"(proxyviewcontainer (label[text=one]), (label[text=two]), (label[text=three]))",
492492
dumpView(componentRoot, true));
493493
});
494494
});
@@ -503,7 +503,7 @@ describe("Renderer E2E", () => {
503503
fixture.detectChanges();
504504

505505
assert.equal(
506-
"(ProxyViewContainer (Label[text=one]), (Label[text=three]))",
506+
"(proxyviewcontainer (label[text=one]), (label[text=three]))",
507507
dumpView(componentRoot, true));
508508
});
509509
});
@@ -518,8 +518,8 @@ describe("Renderer E2E", () => {
518518
fixture.detectChanges();
519519

520520
assert.equal(
521-
"(ProxyViewContainer " +
522-
"(Label[text=one]), (Label[text=new]), (Label[text=two]), (Label[text=three]))",
521+
"(proxyviewcontainer " +
522+
"(label[text=one]), (label[text=new]), (label[text=two]), (label[text=three]))",
523523
dumpView(componentRoot, true));
524524
});
525525
});

Diff for: tests/app/tests/snippets.ts

+3-21
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
11
// make sure you import mocha-config before @angular/core
22
import { assert } from "./test-config";
33

4-
import { NavigationEnd, NavigationStart } from "@angular/router";
5-
import { Subscription } from "rxjs";
6-
74
import { GestureComponent } from "../snippets/gestures.component";
85
import { LayoutsComponent } from "../snippets/layouts.component";
96
import { IconFontComponent } from "../snippets/icon-font.component";
107

11-
import { PageNavigationApp } from "../snippets/navigation/page-outlet";
12-
import { NavigationApp } from "../snippets/navigation/router-outlet";
13-
import { FirstComponent, SecondComponent } from "../snippets/navigation/navigation-common";
14-
import { routes } from "../snippets/navigation/app.routes";
15-
import {
16-
HeaderComponent,
17-
ItemComponent,
18-
DataService,
19-
ListTemplateSelectorTest,
20-
} from "../snippets/list-view/template-selector.component";
21-
22-
import { device, platformNames, isIOS } from "platform";
23-
import {nsTestBedAfterEach, nsTestBedBeforeEach, nsTestBedRender} from "nativescript-angular/testing";
24-
import {ComponentRef} from "@angular/core";
8+
import { nsTestBedAfterEach, nsTestBedBeforeEach, nsTestBedRender } from "nativescript-angular/testing";
9+
import { ComponentRef } from "@angular/core";
2510

2611
describe("Snippets", () => {
2712

@@ -44,14 +29,11 @@ describe("Snippets", () => {
4429
});
4530
});
4631

47-
// TODO: Skip list-view test until karma test launcher double navigate bug is fixed
48-
(isIOS ? it.skip : it)("Icon-font snippets can be loaded", (done) => {
32+
it("Icon-font snippets can be loaded", () => {
4933
return nsTestBedRender(IconFontComponent).then((fixture) => {
5034
const componentRef: ComponentRef<IconFontComponent> = fixture.componentRef;
5135
const componentInstance = componentRef.instance;
5236
assert.instanceOf(componentInstance, IconFontComponent);
53-
// Works around a "dehydrated change detector" exception.
54-
setTimeout(done, 10);
5537
});
5638
});
5739
});

Diff for: tests/app/tests/test-utils.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ function getChildren(view: View): Array<View> {
1212
}
1313

1414
export function dumpView(view: View, verbose: boolean = false): string {
15-
let nodeName = (<any>view).nodeName;
15+
let nodeName: string = (<any>view).nodeName;
1616
if (!nodeName) {
1717
// Strip off the source
18-
nodeName = view.toString().replace(/(@[^;]*;)/g,'');
18+
nodeName = view.toString().replace(/(@[^;]*;)/g, '');
1919
}
20+
nodeName = nodeName.toLocaleLowerCase();
21+
2022
let output = ["(", nodeName];
2123
if (verbose) {
2224
if (view instanceof TextBase) {

0 commit comments

Comments
 (0)