Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore(test): Some tests implemented using async
  • Loading branch information
vakrilov committed May 25, 2018
commit 6d0f9055853195df78c25f4773589b3d8b51a3c6
14 changes: 6 additions & 8 deletions tests/app/tests/list-view-tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert } from "./test-config";
import { Component, Input } from "@angular/core";
import { ComponentFixture } from "@angular/core/testing";
import { ComponentFixture, async } from "@angular/core/testing";
import { nsTestBedAfterEach, nsTestBedBeforeEach, nsTestBedRender } from "nativescript-angular/testing";
// import trace = require("trace");
// trace.setCategories("ns-list-view, " + trace.categories.Navigation);
Expand Down Expand Up @@ -84,20 +84,18 @@ describe("ListView-tests", () => {
]));
afterEach(nsTestBedAfterEach(false));

it("setupItemView is called for every item", (done) => {
it("setupItemView is called for every item", async(() => {
nsTestBedRender(TestListViewComponent)
.then((fixture: ComponentFixture<TestListViewComponent>) => {
const component = fixture.componentRef.instance;
assert.equal(component.counter, 3);
done();
});
});
}));


it("itemTemplateSelector selects templates", (done) => {
it("itemTemplateSelector selects templates", async(() => {
nsTestBedRender(TestListViewSelectorComponent).then(() => {
assert.deepEqual(testTemplates, {first: 2, second: 1});
done();
assert.deepEqual(testTemplates, { first: 2, second: 1 });
});
});
}));
});
14 changes: 6 additions & 8 deletions tests/app/tests/modal-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { Page } from "ui/page";
import { topmost } from "ui/frame";
import { ModalDialogParams, ModalDialogService } from "nativescript-angular/directives/dialogs";

import { device, platformNames } from "platform";
import { device, isIOS } from "platform";

import { ComponentFixture } from "@angular/core/testing";
import { ComponentFixture, async } from "@angular/core/testing";
import { nsTestBedRender, nsTestBedAfterEach, nsTestBedBeforeEach } from "nativescript-angular/testing";
import { NSLocationStrategy } from "nativescript-angular/router/ns-location-strategy";
import { FrameService } from "nativescript-angular";
import { FakeFrameService } from "./ns-location-strategy";
const CLOSE_WAIT = (device.os === platformNames.ios) ? 1000 : 0;
const CLOSE_WAIT = isIOS ? 1000 : 0;

@Component({
selector: "modal-comp",
Expand Down Expand Up @@ -74,17 +74,15 @@ describe("modal-dialog", () => {
});


it("showModal throws when there is no viewContainer provided", (done) => {
it("showModal throws when there is no viewContainer provided", async(() => {
nsTestBedRender(FailComponent)
.then((fixture: ComponentFixture<FailComponent>) => {
const service = <ModalDialogService>fixture.componentRef.instance.service;
assert.throws(() => service.showModal(ModalComponent, {}),
"No viewContainerRef: Make sure you pass viewContainerRef in ModalDialogOptions."
);
})
.then(() => done())
.catch((e) => done(e));
});
});
}));

it("showModal succeeds when there is viewContainer provided", (done) => {
nsTestBedRender(SuccessComponent)
Expand Down
12 changes: 5 additions & 7 deletions tests/app/tests/renderer-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import * as view from "tns-core-modules/ui/core/view";
import { isIOS } from "tns-core-modules/platform";
import { View, fontInternalProperty, backgroundInternalProperty } from "tns-core-modules/ui/core/view"
import { nsTestBedAfterEach, nsTestBedBeforeEach, nsTestBedRender } from "nativescript-angular/testing";
import { ComponentFixture, TestBed } from "@angular/core/testing";
import { ComponentFixture, TestBed, async } from "@angular/core/testing";
import { Observable, ReplaySubject } from "rxjs";

@Component({
Expand Down Expand Up @@ -308,14 +308,13 @@ describe("Renderer E2E", () => {
});
});

it("executes events inside NgZone when listen is called inside NgZone", (done) => {
it("executes events inside NgZone when listen is called inside NgZone", async(() => {
const eventName = "someEvent";
const view = new StackLayout();
const eventArg = { eventName, object: view };
const callback = (arg) => {
assert.equal(arg, eventArg);
assert.isTrue(NgZone.isInAngularZone(), "Event should be executed inside NgZone");
done();
};

nsTestBedRender(ZonedRenderer).then((fixture: ComponentFixture<ZonedRenderer>) => {
Expand All @@ -330,16 +329,15 @@ describe("Renderer E2E", () => {
}, 10);
});

});
}));

it("executes events inside NgZone when listen is called outside NgZone", (done) => {
it("executes events inside NgZone when listen is called outside NgZone", async(() => {
const eventName = "someEvent";
const view = new StackLayout();
const eventArg = { eventName, object: view };
const callback = (arg) => {
assert.equal(arg, eventArg);
assert.isTrue(NgZone.isInAngularZone(), "Event should be executed inside NgZone");
done();
};
nsTestBedRender(ZonedRenderer).then((fixture: ComponentFixture<ZonedRenderer>) => {
fixture.ngZone.runOutsideAngular(() => {
Expand All @@ -348,7 +346,7 @@ describe("Renderer E2E", () => {
view.notify(eventArg);
});
});
});
}));

describe("Structural directives", () => {
it("ngIf hides component when false", () => {
Expand Down