Skip to content

Commit 2807e99

Browse files
chore: cleanup and remove some diff noise from a few tests
1 parent 20d45ee commit 2807e99

File tree

3 files changed

+48
-62
lines changed

3 files changed

+48
-62
lines changed

nativescript-angular/testing/src/util.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ export function nTestBedBeforeEach(
7272
imports: [
7373
NativeScriptModule, NativeScriptTestingModule, CommonModule
7474
],
75-
providers: [
76-
...NATIVESCRIPT_TESTING_PROVIDERS,
77-
],
78-
entryComponents: [...entryComponents]
75+
providers: NATIVESCRIPT_TESTING_PROVIDERS,
76+
exports: entryComponents,
77+
declarations: entryComponents,
78+
entryComponents: entryComponents
7979
})
8080
class EntryComponentsTestModule {
8181
}
@@ -84,7 +84,7 @@ export function nTestBedBeforeEach(
8484
platformBrowserDynamicTesting(NS_COMPILER_PROVIDERS)
8585
);
8686
TestBed.configureTestingModule({
87-
declarations: [...components, ...entryComponents],
87+
declarations: [...components],
8888
imports: [...imports],
8989
providers: [...providers],
9090
});

tests/app/tests/detached-loader-tests.ts

+19-25
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,21 @@ import {DetachedLoader} from 'nativescript-angular/common/detached-loader';
44
import {nTestBedAfterEach, nTestBedBeforeEach, nTestBedRender} from 'nativescript-angular/testing';
55

66
@Component({
7-
template: `
8-
<StackLayout><Label text="COMPONENT"></Label></StackLayout>`
7+
template: `<StackLayout><Label text="COMPONENT"></Label></StackLayout>`
98
})
10-
class TestComponent {
11-
}
9+
class TestComponent { }
1210

1311

1412
class LoaderComponentBase {
1513
@ViewChild(DetachedLoader) public loader: DetachedLoader;
1614

1715
public ready: Promise<LoaderComponentBase>;
1816
private resolve;
19-
2017
constructor() {
2118
this.ready = new Promise((reslove, reject) => {
2219
this.resolve = reslove;
2320
});
2421
}
25-
2622
ngAfterViewInit() {
2723
console.log("!!! ngAfterViewInit -> loader: " + this.loader);
2824
this.resolve(this);
@@ -32,43 +28,41 @@ class LoaderComponentBase {
3228
@Component({
3329
selector: "loader-component-on-push",
3430
template: `
35-
<StackLayout>
36-
<DetachedContainer #loader></DetachedContainer>
37-
</StackLayout>
31+
<StackLayout>
32+
<DetachedContainer #loader></DetachedContainer>
33+
</StackLayout>
3834
`
3935
})
40-
export class LoaderComponent extends LoaderComponentBase {
41-
}
36+
export class LoaderComponent extends LoaderComponentBase {}
4237

4338
@Component({
4439
selector: "loader-component-on-push",
4540
changeDetection: ChangeDetectionStrategy.OnPush,
4641
template: `
47-
<StackLayout>
48-
<DetachedContainer #loader></DetachedContainer>
49-
</StackLayout>
42+
<StackLayout>
43+
<DetachedContainer #loader></DetachedContainer>
44+
</StackLayout>
5045
`
5146
})
52-
export class LoaderComponentOnPush extends LoaderComponentBase {
53-
}
47+
export class LoaderComponentOnPush extends LoaderComponentBase { }
5448

55-
// TODO(JD): These tests MOSTLY work, but demonstrate an annoying bug I've noticed sometimes with @ViewChild
49+
// TODO(JD): These tests should work, but demonstrate an annoying bug I've noticed sometimes with @ViewChild
5650
//
57-
// @vakrilov can you check this out? The @ViewChild(DetachedLoader) on LoaderComponentBase fails. If you change
58-
// the lookup to be the string name i.e. `@ViewChild('loader')` the result is different, but you get an
59-
// ElementRef that you have to reference .nativeElement on. I'm very confused by this behavior, can you
60-
// shed some light?
61-
xdescribe("DetachedLoader", () => {
51+
// The @ViewChild(DetachedLoader) on LoaderComponentBase fails. Can anyone shed some light on why?
52+
describe("DetachedLoader", () => {
6253

63-
beforeEach(nTestBedBeforeEach([LoaderComponent, LoaderComponentOnPush, TestComponent], [], [], [TestComponent]));
54+
beforeEach(nTestBedBeforeEach([LoaderComponent, LoaderComponentOnPush], [], [], [TestComponent]));
6455
afterEach(nTestBedAfterEach());
6556

6657
it("creates component", (done) => {
58+
let component: LoaderComponent;
59+
6760
nTestBedRender(LoaderComponent)
6861
.then((fixture) => {
69-
const component: LoaderComponent = fixture.componentRef.instance;
70-
return component.loader.loadComponent(TestComponent);
62+
component = fixture.componentRef.instance;
63+
return component.ready;
7164
})
65+
.then(() => component.loader.loadComponent(TestComponent))
7266
.then(() => done())
7367
.catch(done);
7468
});

tests/app/tests/list-view-tests.ts

+24-32
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import {assert} from './test-config';
2-
import {Component, Input} from '@angular/core';
3-
import {ComponentFixture} from '@angular/core/testing';
4-
import {nTestBedAfterEach, nTestBedBeforeEach, nTestBedRender} from 'nativescript-angular/testing';
5-
1+
import { assert } from "./test-config";
2+
import { Component, Input } from "@angular/core";
3+
import { ComponentFixture } from "@angular/core/testing";
4+
import { nTestBedAfterEach, nTestBedBeforeEach, nTestBedRender } from "nativescript-angular/testing";
65
// import trace = require("trace");
76
// trace.setCategories("ns-list-view, " + trace.categories.Navigation);
87
// trace.enable();
98

109
class DataItem {
11-
constructor(public id: number, public name: string) {
12-
}
10+
constructor(public id: number, public name: string) { }
1311
}
1412

1513
const ITEMS = [
@@ -24,22 +22,19 @@ let testTemplates: { first: number, second: number };
2422
@Component({
2523
selector: "list-view-setupItemView",
2624
template: `
27-
<GridLayout>
28-
<ListView [items]="myItems" (setupItemView)="onSetupItemView($event)">
29-
<ng-template let-item="item">
30-
<Label [text]='"[" + item.id +"] " + item.name'></Label>
31-
</ng-template>
32-
</ListView>
33-
</GridLayout>
25+
<GridLayout>
26+
<ListView [items]="myItems" (setupItemView)="onSetupItemView($event)">
27+
<ng-template let-item="item">
28+
<Label [text]='"[" + item.id +"] " + item.name'></Label>
29+
</ng-template>
30+
</ListView>
31+
</GridLayout>
3432
`
3533
})
3634
export class TestListViewComponent {
3735
public myItems: Array<DataItem> = ITEMS;
3836
public counter: number = 0;
39-
40-
onSetupItemView(args) {
41-
this.counter++;
42-
}
37+
onSetupItemView(args) { this.counter++; }
4338
}
4439

4540
@Component({
@@ -61,27 +56,24 @@ export class ItemTemplateComponent {
6156
@Component({
6257
selector: "list-with-template-selector",
6358
template: `
64-
<GridLayout>
65-
<ListView [items]="myItems" [itemTemplateSelector]="templateSelector">
66-
<ng-template nsTemplateKey="first">
67-
<item-component templateName="first"></item-component>
68-
</ng-template>
69-
<ng-template nsTemplateKey="second" let-item="item">
70-
<item-component templateName="second"></item-component>
71-
</ng-template>
72-
</ListView>
73-
</GridLayout>
59+
<GridLayout>
60+
<ListView [items]="myItems" [itemTemplateSelector]="templateSelector">
61+
<ng-template nsTemplateKey="first">
62+
<item-component templateName="first"></item-component>
63+
</ng-template>
64+
<ng-template nsTemplateKey="second" let-item="item">
65+
<item-component templateName="second"></item-component>
66+
</ng-template>
67+
</ListView>
68+
</GridLayout>
7469
`
7570
})
7671
export class TestListViewSelectorComponent {
7772
public myItems: Array<DataItem> = ITEMS;
7873
public templateSelector = (item: DataItem, index: number, items: any) => {
7974
return (item.id % 2 === 0) ? "first" : "second";
80-
};
81-
82-
constructor() {
83-
testTemplates = {first: 0, second: 0};
8475
}
76+
constructor() { testTemplates = { first: 0, second: 0 }; }
8577
}
8678

8779
describe("ListView-tests", () => {

0 commit comments

Comments
 (0)