diff --git a/nativescript-angular/platform-common.ts b/nativescript-angular/platform-common.ts index b37262098..d38f3f2d1 100644 --- a/nativescript-angular/platform-common.ts +++ b/nativescript-angular/platform-common.ts @@ -67,7 +67,10 @@ export class NativeScriptSanitizer extends Sanitizer { } // Add a fake polyfill for the document object -(global).document = (global).document || {}; +(global).document = (global).document || { + getElementById: () => { return undefined; } +}; + const doc = (global).document; doc.body = Object.assign(doc.body || {}, { isOverride: true, diff --git a/nativescript-angular/testing/src/util.ts b/nativescript-angular/testing/src/util.ts index 52859e89e..3cc5b8f8f 100644 --- a/nativescript-angular/testing/src/util.ts +++ b/nativescript-angular/testing/src/util.ts @@ -125,7 +125,10 @@ export function nsTestBedAfterEach(resetEnv = true, resetFn = nsTestBedInit) { const root = testingRootView() as LayoutBase; const fixtures = activeTestFixtures.pop(); fixtures.forEach((fixture) => { - root.removeChild(fixture.nativeElement); + const fixtureView = fixture.nativeElement; + if (fixtureView.parent === root) { + root.removeChild(fixtureView); + } fixture.destroy(); }); TestBed.resetTestingModule(); @@ -144,10 +147,10 @@ export function nsTestBedRender(componentType: Type): Promise { const list = activeTestFixtures[activeTestFixtures.length - 1]; diff --git a/tests/app/tests/platform-filter-components.ts b/tests/app/tests/platform-filter-components.ts index fff8368ec..d239c495d 100644 --- a/tests/app/tests/platform-filter-components.ts +++ b/tests/app/tests/platform-filter-components.ts @@ -47,7 +47,7 @@ describe("Platform filter directives", () => { return nsTestBedRender(IosSpecificComponent).then((fixture) => { const componentRef = fixture.componentRef; const componentRoot = componentRef.instance.elementRef.nativeElement; - assert.isTrue(dumpView(componentRoot, true).indexOf("(Label[text=IOS])") >= 0); + assert.isTrue(dumpView(componentRoot, true).indexOf("(label[text=IOS])") >= 0); }); }); it("does not render android specific content", () => { @@ -62,7 +62,7 @@ describe("Platform filter directives", () => { const componentRef = fixture.componentRef; const componentRoot = componentRef.instance.elementRef.nativeElement; assert.equal( - "(ProxyViewContainer (StackLayout (Label[text=IOS])))", + "(proxyviewcontainer (stacklayout (label[text=IOS])))", dumpView(componentRoot, true)); }); }); @@ -79,7 +79,7 @@ describe("Platform filter directives", () => { return nsTestBedRender(AndroidSpecificComponent).then((fixture) => { const componentRef = fixture.componentRef; const componentRoot = componentRef.instance.elementRef.nativeElement; - assert.isTrue(dumpView(componentRoot, true).indexOf("(Label[text=ANDROID])") >= 0); + assert.isTrue(dumpView(componentRoot, true).indexOf("(label[text=ANDROID])") >= 0); }); }); it("does not render ios specific content", () => { @@ -94,7 +94,7 @@ describe("Platform filter directives", () => { const componentRef = fixture.componentRef; const componentRoot = componentRef.instance.elementRef.nativeElement; assert.equal( - "(ProxyViewContainer (StackLayout (Label[text=ANDROID])))", + "(proxyviewcontainer (stacklayout (label[text=ANDROID])))", dumpView(componentRoot, true)); }); }); diff --git a/tests/app/tests/renderer-tests.ts b/tests/app/tests/renderer-tests.ts index 94c0a4e7e..ae6c5346b 100644 --- a/tests/app/tests/renderer-tests.ts +++ b/tests/app/tests/renderer-tests.ts @@ -262,7 +262,7 @@ describe("Renderer E2E", () => { return nsTestBedRender(LayoutWithLabel).then((fixture) => { const componentRef: ComponentRef = fixture.componentRef; const componentRoot = componentRef.instance.elementRef.nativeElement; - assert.equal("(ProxyViewContainer (StackLayout (Label)))", dumpView(componentRoot)); + assert.equal("(proxyviewcontainer (stacklayout (label)))", dumpView(componentRoot)); }); }); @@ -270,7 +270,7 @@ describe("Renderer E2E", () => { return nsTestBedRender(LabelContainer).then((fixture) => { const componentRef: ComponentRef = fixture.componentRef; const componentRoot = componentRef.instance.elementRef.nativeElement; - assert.equal("(ProxyViewContainer (GridLayout (ProxyViewContainer (Label))))", dumpView(componentRoot)); + assert.equal("(proxyviewcontainer (gridlayout (proxyviewcontainer (label))))", dumpView(componentRoot)); }); }); @@ -279,7 +279,7 @@ describe("Renderer E2E", () => { const componentRef: ComponentRef = fixture.componentRef; const componentRoot = componentRef.instance.elementRef.nativeElement; assert.equal( - "(ProxyViewContainer (GridLayout (ProxyViewContainer (StackLayout (Button)))))", + "(proxyviewcontainer (gridlayout (proxyviewcontainer (stacklayout (button)))))", dumpView(componentRoot)); }); }); @@ -355,7 +355,7 @@ describe("Renderer E2E", () => { return nsTestBedRender(NgIfLabel).then((fixture) => { const componentRef: ComponentRef = fixture.componentRef; const componentRoot = componentRef.instance.elementRef.nativeElement; - assert.equal("(ProxyViewContainer)", dumpView(componentRoot)); + assert.equal("(proxyviewcontainer)", dumpView(componentRoot)); }); }); @@ -367,7 +367,7 @@ describe("Renderer E2E", () => { component.show = true; fixture.detectChanges(); - assert.equal("(ProxyViewContainer (Label))", dumpView(componentRoot)); + assert.equal("(proxyviewcontainer (label))", dumpView(componentRoot)); }); }); @@ -380,7 +380,7 @@ describe("Renderer E2E", () => { component.show = true; fixture.detectChanges(); assert.equal( - "(ProxyViewContainer (StackLayout (Label), (Button)))", + "(proxyviewcontainer (stacklayout (label), (button)))", dumpView(componentRoot)); }); }); @@ -394,13 +394,13 @@ describe("Renderer E2E", () => { component.show = true; fixture.detectChanges(); assert.equal( - "(ProxyViewContainer " + - "(StackLayout " + - "(Label[text=1]), " + - "(Label[text=2]), " + - "(Label[text=3]), " + - "(Label[text=4]), " + // the content to be conditionally displayed - "(Label[text=5])" + + "(proxyviewcontainer " + + "(stacklayout " + + "(label[text=1]), " + + "(label[text=2]), " + + "(label[text=3]), " + + "(label[text=4]), " + // the content to be conditionally displayed + "(label[text=5])" + ")" + ")", dumpView(componentRoot, true)); @@ -416,9 +416,9 @@ describe("Renderer E2E", () => { fixture.detectChanges(); assert.equal( - "(ProxyViewContainer " + - "(StackLayout " + - "(Label[text=If])" + + "(proxyviewcontainer " + + "(stacklayout " + + "(label[text=If])" + ")" + ")", @@ -435,9 +435,9 @@ describe("Renderer E2E", () => { component.show = false; fixture.detectChanges(); assert.equal( - "(ProxyViewContainer " + - "(StackLayout " + - "(Label[text=Else])" + + "(proxyviewcontainer " + + "(stacklayout " + + "(label[text=Else])" + ")" + ")", @@ -453,9 +453,9 @@ describe("Renderer E2E", () => { fixture.detectChanges(); assert.equal( - "(ProxyViewContainer " + - "(StackLayout " + - "(Label[text=Then])" + + "(proxyviewcontainer " + + "(stacklayout " + + "(label[text=Then])" + ")" + ")", @@ -473,9 +473,9 @@ describe("Renderer E2E", () => { component.show = false; fixture.detectChanges(); assert.equal( - "(ProxyViewContainer " + - "(StackLayout " + - "(Label[text=Else])" + + "(proxyviewcontainer " + + "(stacklayout " + + "(label[text=Else])" + ")" + ")", @@ -488,7 +488,7 @@ describe("Renderer E2E", () => { const componentRef: ComponentRef = fixture.componentRef; const componentRoot = componentRef.instance.elementRef.nativeElement; assert.equal( - "(ProxyViewContainer (Label[text=one]), (Label[text=two]), (Label[text=three]))", + "(proxyviewcontainer (label[text=one]), (label[text=two]), (label[text=three]))", dumpView(componentRoot, true)); }); }); @@ -503,7 +503,7 @@ describe("Renderer E2E", () => { fixture.detectChanges(); assert.equal( - "(ProxyViewContainer (Label[text=one]), (Label[text=three]))", + "(proxyviewcontainer (label[text=one]), (label[text=three]))", dumpView(componentRoot, true)); }); }); @@ -518,8 +518,8 @@ describe("Renderer E2E", () => { fixture.detectChanges(); assert.equal( - "(ProxyViewContainer " + - "(Label[text=one]), (Label[text=new]), (Label[text=two]), (Label[text=three]))", + "(proxyviewcontainer " + + "(label[text=one]), (label[text=new]), (label[text=two]), (label[text=three]))", dumpView(componentRoot, true)); }); }); diff --git a/tests/app/tests/snippets.ts b/tests/app/tests/snippets.ts index 793b33421..b97b3285a 100644 --- a/tests/app/tests/snippets.ts +++ b/tests/app/tests/snippets.ts @@ -1,27 +1,12 @@ // make sure you import mocha-config before @angular/core import { assert } from "./test-config"; -import { NavigationEnd, NavigationStart } from "@angular/router"; -import { Subscription } from "rxjs"; - import { GestureComponent } from "../snippets/gestures.component"; import { LayoutsComponent } from "../snippets/layouts.component"; import { IconFontComponent } from "../snippets/icon-font.component"; -import { PageNavigationApp } from "../snippets/navigation/page-outlet"; -import { NavigationApp } from "../snippets/navigation/router-outlet"; -import { FirstComponent, SecondComponent } from "../snippets/navigation/navigation-common"; -import { routes } from "../snippets/navigation/app.routes"; -import { - HeaderComponent, - ItemComponent, - DataService, - ListTemplateSelectorTest, -} from "../snippets/list-view/template-selector.component"; - -import { device, platformNames, isIOS } from "platform"; -import {nsTestBedAfterEach, nsTestBedBeforeEach, nsTestBedRender} from "nativescript-angular/testing"; -import {ComponentRef} from "@angular/core"; +import { nsTestBedAfterEach, nsTestBedBeforeEach, nsTestBedRender } from "nativescript-angular/testing"; +import { ComponentRef } from "@angular/core"; describe("Snippets", () => { @@ -44,14 +29,11 @@ describe("Snippets", () => { }); }); - // TODO: Skip list-view test until karma test launcher double navigate bug is fixed - (isIOS ? it.skip : it)("Icon-font snippets can be loaded", (done) => { + it("Icon-font snippets can be loaded", () => { return nsTestBedRender(IconFontComponent).then((fixture) => { const componentRef: ComponentRef = fixture.componentRef; const componentInstance = componentRef.instance; assert.instanceOf(componentInstance, IconFontComponent); - // Works around a "dehydrated change detector" exception. - setTimeout(done, 10); }); }); }); diff --git a/tests/app/tests/test-utils.ts b/tests/app/tests/test-utils.ts index d168f2caf..5e78de08a 100644 --- a/tests/app/tests/test-utils.ts +++ b/tests/app/tests/test-utils.ts @@ -12,11 +12,13 @@ function getChildren(view: View): Array { } export function dumpView(view: View, verbose: boolean = false): string { - let nodeName = (view).nodeName; + let nodeName: string = (view).nodeName; if (!nodeName) { // Strip off the source - nodeName = view.toString().replace(/(@[^;]*;)/g,''); + nodeName = view.toString().replace(/(@[^;]*;)/g, ''); } + nodeName = nodeName.toLocaleLowerCase(); + let output = ["(", nodeName]; if (verbose) { if (view instanceof TextBase) {