Skip to content

Commit a6a8848

Browse files
committed
fix: unit tests part 1
1 parent 04ef934 commit a6a8848

File tree

10 files changed

+45
-27
lines changed

10 files changed

+45
-27
lines changed

apps/nativescript-demo-ng/project.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
"uglify": false,
3939
"release": false,
4040
"forDevice": false,
41-
"prepare": false,
42-
"flags": "--env.commonjs"
41+
"prepare": false
4342
},
4443
"dependsOn": [
4544
"^build"
@@ -58,8 +57,7 @@
5857
"{workspaceRoot}/coverage/apps/nativescript-demo-ng"
5958
],
6059
"options": {
61-
"coverage": false,
62-
"flags": "--env.commonjs"
60+
"coverage": false
6361
},
6462
"dependsOn": [
6563
"^build"

apps/nativescript-demo-ng/src/tests/detached-loader-tests.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// make sure you import mocha-config before @angular/core
22
import { ChangeDetectionStrategy, Component, Directive, NgModule, NO_ERRORS_SCHEMA, ViewChild } from '@angular/core';
33
import { TestBed } from '@angular/core/testing';
4-
import { DetachedLoader, NativeScriptModule } from '@nativescript/angular';
4+
import { DetachedLoader, NativeScriptCommonModule, NativeScriptModule } from '@nativescript/angular';
55
import { NativeScriptTestingModule } from '@nativescript/angular/testing';
66
// import { NS_COMPILER_PROVIDERS } from "@nativescript/angular/platform";
77
import { CommonModule } from '@angular/common';
88

99
@Component({
1010
template: `<StackLayout><Label text="COMPONENT"></Label></StackLayout>`,
11+
imports: [NativeScriptCommonModule],
1112
schemas: [NO_ERRORS_SCHEMA],
1213
})
1314
export class TestComponent {}
@@ -24,7 +25,7 @@ class LoaderComponentBase {
2425
<DetachedContainer #loader></DetachedContainer>
2526
</StackLayout>
2627
`,
27-
imports: [DetachedLoader],
28+
imports: [DetachedLoader, NativeScriptCommonModule],
2829
schemas: [NO_ERRORS_SCHEMA],
2930
})
3031
export class LoaderComponent extends LoaderComponentBase {}
@@ -37,14 +38,14 @@ export class LoaderComponent extends LoaderComponentBase {}
3738
<DetachedContainer #loader></DetachedContainer>
3839
</StackLayout>
3940
`,
40-
imports: [DetachedLoader],
41+
imports: [DetachedLoader, NativeScriptCommonModule],
4142
schemas: [NO_ERRORS_SCHEMA],
4243
})
4344
// eslint-disable-next-line @angular-eslint/component-class-suffix
4445
export class LoaderComponentOnPush extends LoaderComponentBase {}
4546

4647
@NgModule({
47-
imports: [LoaderComponent, LoaderComponentOnPush, TestComponent],
48+
imports: [LoaderComponent, LoaderComponentOnPush, TestComponent, NativeScriptCommonModule],
4849
schemas: [NO_ERRORS_SCHEMA],
4950
})
5051
export class EntryComponentsTestModule {}

apps/nativescript-demo-ng/src/tests/detached-utils-tests.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import {
1313
ViewContainerRef,
1414
} from '@angular/core';
1515
import { ComponentFixture, TestBed } from '@angular/core/testing';
16-
import { generateDetachedLoader, generateNativeScriptView, NgViewRef } from '@nativescript/angular';
16+
import { generateDetachedLoader, generateNativeScriptView, NativeScriptCommonModule, NgViewRef } from '@nativescript/angular';
1717
import { GridLayout, ProxyViewContainer } from '@nativescript/core';
1818

1919
@Component({
2020
template: `<ng-container #vc></ng-container><ng-template #template><GridLayout></GridLayout></ng-template>`,
21+
imports: [NativeScriptCommonModule],
2122
schemas: [NO_ERRORS_SCHEMA],
2223
})
2324
export class GenerateViewComponent {
@@ -28,12 +29,13 @@ export class GenerateViewComponent {
2829

2930
@Component({
3031
template: `<GridLayout></GridLayout>`,
32+
imports: [NativeScriptCommonModule],
3133
schemas: [NO_ERRORS_SCHEMA],
3234
})
3335
export class GeneratedComponent {}
3436

3537
@NgModule({
36-
imports: [GeneratedComponent, GenerateViewComponent],
38+
imports: [GeneratedComponent, GenerateViewComponent, NativeScriptCommonModule],
3739
schemas: [NO_ERRORS_SCHEMA],
3840
})
3941
export class GeneratedModule {}

apps/nativescript-demo-ng/src/tests/http-client-ns-backend.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import { NSFileSystem } from '@nativescript/angular';
33
import { NsHttpBackEnd } from '@nativescript/angular';
44

5+
import { EnvironmentInjector, createEnvironmentInjector, runInInjectionContext } from '@angular/core';
6+
import { TestBed } from '@angular/core/testing';
57
import { HttpRequest, HttpResponse, HttpErrorResponse } from '@angular/common/http';
68
import { XhrFactory } from '@angular/common';
7-
import { File } from '@nativescript/core/file-system';
89

910
class NSFileSystemMock implements NSFileSystem {
1011
public currentApp(): any {
@@ -36,7 +37,10 @@ describe('NsHttpBackEnd ', () => {
3637
let backend: NsHttpBackEnd;
3738

3839
beforeEach(() => {
39-
backend = new NsHttpBackEnd(new XhrFactoryMock(), new NSFileSystemMock());
40+
TestBed.configureTestingModule({});
41+
const parentInjector = TestBed.inject(EnvironmentInjector);
42+
const injector = createEnvironmentInjector([], parentInjector);
43+
backend = runInInjectionContext(injector, () => new NsHttpBackEnd(new XhrFactoryMock(), new NSFileSystemMock()));
4044
});
4145

4246
it("should work with local files prefixed with '~'", (done) => {

apps/nativescript-demo-ng/src/tests/list-view-tests.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, Input, NO_ERRORS_SCHEMA, ViewChild } from '@angular/core';
22
import { TestBed, waitForAsync } from '@angular/core/testing';
3-
import { ListViewComponent, TemplateKeyDirective } from '@nativescript/angular';
3+
import { ListViewComponent, NativeScriptCommonModule, TemplateKeyDirective } from '@nativescript/angular';
44
// import trace = require("trace");
55
// trace.setCategories("ns-list-view, " + trace.categories.Navigation);
66
// trace.enable();
@@ -27,7 +27,7 @@ let testTemplates: { first: number; second: number };
2727
</ListView>
2828
</GridLayout>
2929
`,
30-
imports: [ListViewComponent],
30+
imports: [ListViewComponent, NativeScriptCommonModule],
3131
schemas: [NO_ERRORS_SCHEMA],
3232
})
3333
export class TestListViewComponent {
@@ -41,6 +41,8 @@ export class TestListViewComponent {
4141
@Component({
4242
selector: 'item-component',
4343
template: `<Label text="template"></Label>`,
44+
imports: [NativeScriptCommonModule],
45+
schemas: [NO_ERRORS_SCHEMA],
4446
})
4547
export class ItemTemplateComponent {
4648
@Input() set templateName(value: any) {
@@ -68,7 +70,7 @@ export class ItemTemplateComponent {
6870
</ListView>
6971
</GridLayout>
7072
`,
71-
imports: [ListViewComponent, TemplateKeyDirective, ItemTemplateComponent],
73+
imports: [ListViewComponent, TemplateKeyDirective, ItemTemplateComponent, NativeScriptCommonModule],
7274
schemas: [NO_ERRORS_SCHEMA],
7375
})
7476
export class TestListViewSelectorComponent {
@@ -101,7 +103,7 @@ export class TestListViewSelectorComponent {
101103
</ListView>
102104
</GridLayout>
103105
`,
104-
imports: [ListViewComponent, TemplateKeyDirective, ItemTemplateComponent],
106+
imports: [ListViewComponent, TemplateKeyDirective, ItemTemplateComponent, NativeScriptCommonModule],
105107
schemas: [NO_ERRORS_SCHEMA],
106108
})
107109
export class TestListViewSelectorWithEventsComponent {

apps/nativescript-demo-ng/src/tests/modal-dialog.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// make sure you import mocha-config before @angular/core
22
import { Component, inject, NgModule, NO_ERRORS_SCHEMA, ViewContainerRef } from '@angular/core';
33
import { TestBed, waitForAsync } from '@angular/core/testing';
4-
import { FrameService, ModalDialogParams, ModalDialogService, NSLocationStrategy, Outlet } from '@nativescript/angular';
4+
import { FrameService, ModalDialogParams, ModalDialogService, NativeScriptCommonModule, NSLocationStrategy, Outlet } from '@nativescript/angular';
55
import { Frame, isIOS } from '@nativescript/core';
66

77
import { FakeFrameService } from './ns-location-strategy.spec';
@@ -10,6 +10,7 @@ const CLOSE_WAIT = isIOS ? 1000 : 0;
1010
@Component({
1111
selector: 'modal-comp',
1212
template: `<Label text="this is modal component" (shownModally)="onShownModally()"></Label>`,
13+
imports: [NativeScriptCommonModule],
1314
schemas: [NO_ERRORS_SCHEMA],
1415
})
1516
export class ModalComponent {
@@ -25,6 +26,7 @@ export class ModalComponent {
2526
selector: 'fail-comp',
2627
providers: [ModalDialogService],
2728
template: `<Label text="This app is doomed"></Label>`,
29+
imports: [NativeScriptCommonModule],
2830
schemas: [NO_ERRORS_SCHEMA],
2931
})
3032
export class FailComponent {
@@ -37,6 +39,7 @@ export class FailComponent {
3739
template: ` <GridLayout margin="20">
3840
<Label text="Modal dialogs"></Label>
3941
</GridLayout>`,
42+
imports: [NativeScriptCommonModule],
4043
schemas: [NO_ERRORS_SCHEMA],
4144
})
4245
export class SuccessComponent {
@@ -47,9 +50,8 @@ export class SuccessComponent {
4750
}
4851

4952
@NgModule({
50-
imports: [FailComponent, SuccessComponent, ModalComponent],
53+
imports: [FailComponent, SuccessComponent, ModalComponent, NativeScriptCommonModule],
5154
exports: [FailComponent, SuccessComponent, ModalComponent],
52-
// entryComponents: [ModalComponent],
5355
schemas: [NO_ERRORS_SCHEMA],
5456
})
5557
export class EntryComponentsTestModule {}
@@ -62,7 +64,7 @@ describe('modal-dialog', () => {
6264
// [ModalComponent]));
6365
beforeEach(() => {
6466
return TestBed.configureTestingModule({
65-
imports: [FailComponent, SuccessComponent, ModalComponent],
67+
imports: [FailComponent, SuccessComponent, ModalComponent, NativeScriptCommonModule],
6668
providers: [{ provide: FrameService, useValue: new FakeFrameService() }, NSLocationStrategy],
6769
}).compileComponents();
6870
});

apps/nativescript-demo-ng/src/tests/platform-filter-components.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// make sure you import mocha-config before @angular/core
22
import { Component, ElementRef, inject, NO_ERRORS_SCHEMA } from '@angular/core';
33
import { TestBed } from '@angular/core/testing';
4-
import { AndroidFilterComponent, DEVICE, IOSFilterComponent, AppleFilterComponent } from '@nativescript/angular';
4+
import { AndroidFilterComponent, DEVICE, IOSFilterComponent, AppleFilterComponent, NativeScriptCommonModule } from '@nativescript/angular';
55
import { platformNames } from '@nativescript/core/platform';
66
import { createDevice, dumpView } from './test-utils.spec';
77
@Component({
88
template: ` <StackLayout>
99
<ios><Label text="IOS"></Label></ios>
1010
</StackLayout>`,
11-
imports: [IOSFilterComponent],
11+
imports: [IOSFilterComponent, NativeScriptCommonModule],
1212
schemas: [NO_ERRORS_SCHEMA],
1313
})
1414
export class IosSpecificComponent {
@@ -19,7 +19,7 @@ export class IosSpecificComponent {
1919
template: ` <StackLayout>
2020
<apple><Label text="Apple"></Label></apple>
2121
</StackLayout>`,
22-
imports: [AppleFilterComponent],
22+
imports: [AppleFilterComponent, NativeScriptCommonModule],
2323
schemas: [NO_ERRORS_SCHEMA],
2424
})
2525
export class AppleSpecificComponent {
@@ -30,7 +30,7 @@ export class AppleSpecificComponent {
3030
template: ` <StackLayout>
3131
<android><Label text="ANDROID"></Label></android>
3232
</StackLayout>`,
33-
imports: [AndroidFilterComponent],
33+
imports: [AndroidFilterComponent, NativeScriptCommonModule],
3434
schemas: [NO_ERRORS_SCHEMA],
3535
})
3636
export class AndroidSpecificComponent {
@@ -41,6 +41,7 @@ export class AndroidSpecificComponent {
4141
template: ` <StackLayout>
4242
<Label android:text="ANDROID" ios:text="IOS"></Label>
4343
</StackLayout>`,
44+
imports: [NativeScriptCommonModule],
4445
schemas: [NO_ERRORS_SCHEMA],
4546
})
4647
export class PlatformSpecificAttributeComponent {

apps/nativescript-demo-ng/src/tests/spans.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
import { Component, ElementRef, NO_ERRORS_SCHEMA, ViewChild } from '@angular/core';
66
import { TestBed } from '@angular/core/testing';
7-
import { NativeScriptModule } from '@nativescript/angular';
7+
import { NativeScriptCommonModule, NativeScriptModule } from '@nativescript/angular';
88
import { TextBase } from '@nativescript/core';
99

1010
const configureComponents = (textBaseElementName: string) => {
@@ -21,6 +21,8 @@ const configureComponents = (textBaseElementName: string) => {
2121
</${textBaseElementName}>`;
2222
@Component({
2323
template,
24+
imports: [NativeScriptCommonModule],
25+
schemas: [NO_ERRORS_SCHEMA],
2426
})
2527
class SpansComponent extends BaseComponent {}
2628

@@ -45,6 +47,8 @@ const configureComponents = (textBaseElementName: string) => {
4547
</${textBaseElementName}>`;
4648
@Component({
4749
template,
50+
imports: [NativeScriptCommonModule],
51+
schemas: [NO_ERRORS_SCHEMA],
4852
})
4953
class DynamicSpansComponent extends BaseComponent {
5054
show = true;
@@ -61,6 +65,8 @@ const configureComponents = (textBaseElementName: string) => {
6165
</${textBaseElementName}>`;
6266
@Component({
6367
template,
68+
imports: [NativeScriptCommonModule],
69+
schemas: [NO_ERRORS_SCHEMA],
6470
})
6571
class DynamicFormattedStringComponent extends BaseComponent {
6672
show = true;

apps/nativescript-demo-ng/src/tests/textnode.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Component, ElementRef, NO_ERRORS_SCHEMA, ViewChild } from '@angular/core';
22
import { TestBed } from '@angular/core/testing';
3-
import { TextNode } from '@nativescript/angular';
3+
import { NativeScriptCommonModule, TextNode } from '@nativescript/angular';
44
import { TextBase } from '@nativescript/core';
55

66
@Component({
77
template: `<Label #textElement>{{ text }}</Label>`,
8+
imports: [NativeScriptCommonModule],
89
schemas: [NO_ERRORS_SCHEMA],
910
})
1011
class TextNodeComponent {
@@ -16,6 +17,7 @@ class TextNodeComponent {
1617
template: `<Label #textElement
1718
><Span>{{ text }}</Span></Label
1819
>`,
20+
imports: [NativeScriptCommonModule],
1921
schemas: [NO_ERRORS_SCHEMA],
2022
})
2123
class TextNodeSpansComponent {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"start": "nx serve",
1212
"build": "npx nx run-many --target=build --exclude=nativescript-demo-ng",
1313
"test.android": "nx test nativescript-demo-ng android",
14-
"test.ios": "nx test nativescript-demo-ng ios",
14+
"test.ios": "npx rimraf apps/nativescript-demo-ng/platforms && nx test nativescript-demo-ng ios",
1515
"lint": "nx workspace-lint && nx lint",
1616
"e2e": "nx e2e",
1717
"affected:apps": "nx affected:apps",

0 commit comments

Comments
 (0)