Skip to content

Commit 7b397df

Browse files
author
vakrilov
committed
chore(test): Some tests implemented using async
1 parent 3339439 commit 7b397df

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

Diff for: tests/app/tests/list-view-tests.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { assert } from "./test-config";
22
import { Component, Input } from "@angular/core";
3-
import { ComponentFixture } from "@angular/core/testing";
3+
import { ComponentFixture, async } from "@angular/core/testing";
44
import { nsTestBedAfterEach, nsTestBedBeforeEach, nsTestBedRender } from "nativescript-angular/testing";
55
// import trace = require("trace");
66
// trace.setCategories("ns-list-view, " + trace.categories.Navigation);
@@ -84,20 +84,18 @@ describe("ListView-tests", () => {
8484
]));
8585
afterEach(nsTestBedAfterEach(false));
8686

87-
it("setupItemView is called for every item", (done) => {
87+
it("setupItemView is called for every item", async(() => {
8888
nsTestBedRender(TestListViewComponent)
8989
.then((fixture: ComponentFixture<TestListViewComponent>) => {
9090
const component = fixture.componentRef.instance;
9191
assert.equal(component.counter, 3);
92-
done();
9392
});
94-
});
93+
}));
9594

9695

97-
it("itemTemplateSelector selects templates", (done) => {
96+
it("itemTemplateSelector selects templates", async(() => {
9897
nsTestBedRender(TestListViewSelectorComponent).then(() => {
99-
assert.deepEqual(testTemplates, {first: 2, second: 1});
100-
done();
98+
assert.deepEqual(testTemplates, { first: 2, second: 1 });
10199
});
102-
});
100+
}));
103101
});

Diff for: tests/app/tests/modal-dialog.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import { Page } from "ui/page";
55
import { topmost } from "ui/frame";
66
import { ModalDialogParams, ModalDialogService } from "nativescript-angular/directives/dialogs";
77

8-
import { device, platformNames } from "platform";
8+
import { device, isIOS } from "platform";
99

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

1717
@Component({
1818
selector: "modal-comp",
@@ -74,17 +74,15 @@ describe("modal-dialog", () => {
7474
});
7575

7676

77-
it("showModal throws when there is no viewContainer provided", (done) => {
77+
it("showModal throws when there is no viewContainer provided", async(() => {
7878
nsTestBedRender(FailComponent)
7979
.then((fixture: ComponentFixture<FailComponent>) => {
8080
const service = <ModalDialogService>fixture.componentRef.instance.service;
8181
assert.throws(() => service.showModal(ModalComponent, {}),
8282
"No viewContainerRef: Make sure you pass viewContainerRef in ModalDialogOptions."
8383
);
84-
})
85-
.then(() => done())
86-
.catch((e) => done(e));
87-
});
84+
});
85+
}));
8886

8987
it("showModal succeeds when there is viewContainer provided", (done) => {
9088
nsTestBedRender(SuccessComponent)

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

+5-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import * as view from "tns-core-modules/ui/core/view";
1414
import { isIOS } from "tns-core-modules/platform";
1515
import { View, fontInternalProperty, backgroundInternalProperty } from "tns-core-modules/ui/core/view"
1616
import { nsTestBedAfterEach, nsTestBedBeforeEach, nsTestBedRender } from "nativescript-angular/testing";
17-
import { ComponentFixture, TestBed } from "@angular/core/testing";
17+
import { ComponentFixture, TestBed, async } from "@angular/core/testing";
1818
import { Observable, ReplaySubject } from "rxjs";
1919

2020
@Component({
@@ -308,14 +308,13 @@ describe("Renderer E2E", () => {
308308
});
309309
});
310310

311-
it("executes events inside NgZone when listen is called inside NgZone", (done) => {
311+
it("executes events inside NgZone when listen is called inside NgZone", async(() => {
312312
const eventName = "someEvent";
313313
const view = new StackLayout();
314314
const eventArg = { eventName, object: view };
315315
const callback = (arg) => {
316316
assert.equal(arg, eventArg);
317317
assert.isTrue(NgZone.isInAngularZone(), "Event should be executed inside NgZone");
318-
done();
319318
};
320319

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

333-
});
332+
}));
334333

335-
it("executes events inside NgZone when listen is called outside NgZone", (done) => {
334+
it("executes events inside NgZone when listen is called outside NgZone", async(() => {
336335
const eventName = "someEvent";
337336
const view = new StackLayout();
338337
const eventArg = { eventName, object: view };
339338
const callback = (arg) => {
340339
assert.equal(arg, eventArg);
341340
assert.isTrue(NgZone.isInAngularZone(), "Event should be executed inside NgZone");
342-
done();
343341
};
344342
nsTestBedRender(ZonedRenderer).then((fixture: ComponentFixture<ZonedRenderer>) => {
345343
fixture.ngZone.runOutsideAngular(() => {
@@ -348,7 +346,7 @@ describe("Renderer E2E", () => {
348346
view.notify(eventArg);
349347
});
350348
});
351-
});
349+
}));
352350

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

0 commit comments

Comments
 (0)