|
1 | 1 | import {ComponentFixture, TestBed} from '@angular/core/testing';
|
2 | 2 | import {NgModule, Type} from '@angular/core';
|
3 |
| -import {topmost} from 'tns-core-modules/ui/frame'; |
4 |
| -import {View} from 'tns-core-modules/ui/core/view'; |
5 | 3 | import {NativeScriptModule} from '../../nativescript.module';
|
6 | 4 | import {platformBrowserDynamicTesting} from '@angular/platform-browser-dynamic/testing';
|
7 | 5 | import {NS_COMPILER_PROVIDERS} from '../../platform';
|
8 | 6 | import {NATIVESCRIPT_TESTING_PROVIDERS, NativeScriptTestingModule} from '../index';
|
9 | 7 | import {CommonModule} from '@angular/common';
|
10 |
| -/** |
11 |
| - * Get a reference to the root application view. |
12 |
| - */ |
13 |
| -export function testingRootView(): View { |
14 |
| - return topmost().currentPage.layoutView; |
15 |
| -} |
16 | 8 |
|
17 | 9 | /**
|
18 | 10 | * Return a promise that resolves after (durationMs) milliseconds
|
@@ -64,47 +56,39 @@ export function nTestBedBeforeEach(
|
64 | 56 | entryComponents: any[] = []) {
|
65 | 57 | return (done) => {
|
66 | 58 | // If there are no entry components we can take the simple path.
|
67 |
| - const hasEntryComponents: boolean = entryComponents.length > 0; |
68 |
| - if (!hasEntryComponents) { |
| 59 | + if (entryComponents.length === 0) { |
69 | 60 | TestBed.configureTestingModule({
|
70 | 61 | declarations: [...components],
|
71 | 62 | providers: [...providers],
|
72 | 63 | imports: [NativeScriptModule, ...imports]
|
73 | 64 | });
|
74 |
| - TestBed.compileComponents() |
75 |
| - .then(() => done()) |
76 |
| - .catch((e) => { |
77 |
| - console.log(`Failed to instantiate test component with error: ${e}`); |
78 |
| - console.log(e.stack); |
79 |
| - done(e); |
80 |
| - }); |
81 |
| - return; |
82 | 65 | }
|
83 |
| - // If there are entry components, we have to reset the entire freakin' testing platform |
84 |
| - // in order to make test bed aware of them. There's got to be a better way... (o_O) |
85 |
| - TestBed.resetTestEnvironment(); |
86 |
| - @NgModule({ |
87 |
| - imports: [ |
88 |
| - NativeScriptModule, |
89 |
| - NativeScriptTestingModule, |
90 |
| - CommonModule, |
91 |
| - ], |
92 |
| - providers: [ |
93 |
| - ...NATIVESCRIPT_TESTING_PROVIDERS, |
94 |
| - ], |
95 |
| - entryComponents: [...entryComponents] |
96 |
| - }) |
97 |
| - class EntryComponentsTestModule { |
| 66 | + else { |
| 67 | + // If there are entry components, we have to reset the testing platform. |
| 68 | + // |
| 69 | + // There's got to be a better way... (o_O) |
| 70 | + TestBed.resetTestEnvironment(); |
| 71 | + @NgModule({ |
| 72 | + imports: [ |
| 73 | + NativeScriptModule, NativeScriptTestingModule, CommonModule |
| 74 | + ], |
| 75 | + providers: [ |
| 76 | + ...NATIVESCRIPT_TESTING_PROVIDERS, |
| 77 | + ], |
| 78 | + entryComponents: [...entryComponents] |
| 79 | + }) |
| 80 | + class EntryComponentsTestModule { |
| 81 | + } |
| 82 | + TestBed.initTestEnvironment( |
| 83 | + EntryComponentsTestModule, |
| 84 | + platformBrowserDynamicTesting(NS_COMPILER_PROVIDERS) |
| 85 | + ); |
| 86 | + TestBed.configureTestingModule({ |
| 87 | + declarations: [...components, ...entryComponents], |
| 88 | + imports: [...imports], |
| 89 | + providers: [...providers], |
| 90 | + }); |
98 | 91 | }
|
99 |
| - TestBed.initTestEnvironment( |
100 |
| - EntryComponentsTestModule, |
101 |
| - platformBrowserDynamicTesting(NS_COMPILER_PROVIDERS) |
102 |
| - ); |
103 |
| - TestBed.configureTestingModule({ |
104 |
| - declarations: [...components, ...entryComponents], |
105 |
| - imports: [...imports], |
106 |
| - providers: [...providers], |
107 |
| - }); |
108 | 92 | TestBed.compileComponents()
|
109 | 93 | .then(() => done())
|
110 | 94 | .catch((e) => {
|
@@ -133,11 +117,8 @@ export function nBasicTestBedInit() {
|
133 | 117 | */
|
134 | 118 | export function nTestBedAfterEach(resetEnv = true, resetFn = nBasicTestBedInit) {
|
135 | 119 | return () => {
|
136 |
| - if (!resetEnv) { |
137 |
| - TestBed.resetTestingModule(); |
138 |
| - } |
139 |
| - else { |
140 |
| - TestBed.resetTestingModule(); |
| 120 | + TestBed.resetTestingModule(); |
| 121 | + if (resetEnv) { |
141 | 122 | TestBed.resetTestEnvironment();
|
142 | 123 | resetFn();
|
143 | 124 | }
|
|
0 commit comments