_From @ignaciolarranaga on September 28, 2016 21:3_
I can not configure a testing module, on the start of the tests it throws:
NativeScript / 9.1 (9.1; iPhone) ../../tests/shared/services/user.service.spec.js at line 0 FAILED
ReferenceError: Can't find variable: Zone
NativeScript / 9.1 (9.1; iPhone): Executed 1 of 0 (1 FAILED) ERROR (0.033 secs / 0 secs)
iOS
Just try to configure a test module
import { TestBed } from "@angular/core/testing";
import { NativeScriptModule } from "nativescript-angular/platform";
import { NativeScriptFormsModule } from "nativescript-angular/forms"
import { NativeScriptHttpModule } from "nativescript-angular/http";
import { UserService } from "../../../shared/services";
import { IdentifiedHttp } from "../../../shared/util";
describe("UserService tests", () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
NativeScriptModule,
NativeScriptFormsModule,
NativeScriptHttpModule,
],
declarations: [ UserService ],
providers: [ IdentifiedHttp ]
});
});
});
_Copied from original issue: NativeScript/NativeScript#2814_
@NathanWalker I saw you were showing examples on tests during the developer day workshop (https://nativescript.github.io/developer-day-workshop/#chapter6.8) and actually being able to configure a TestBed, some clue you can give me on why it is not finding the Zone ?.
Thanks in advance!
related to #478
try this:
import 'nativescript-angular/zone.js/dist/zone-nativescript';
import {BrowserDynamicTestingModule,platformBrowserDynamicTesting} from '@angular/platform-browser-dynamic/testing';
import {NS_COMPILER_PROVIDERS} from 'nativescript-angular/platform';
import {TestBed} from '@angular/core/testing';
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(NS_COMPILER_PROVIDERS));
worked for me
I get
TypeError: undefined is not an object (evaluating 'ProxyZoneSpec.assertPresent') (line 178439)
resetFakeAsyncZone
attemptSync
run
execute
execute
queueRunnerFactory
execute
fn
attemptAsync
run
execute
execute
queueRunnerFactory
fn
attemptAsync
run
execute
invokeTask
TestBed isn't supported officially supported yet. It seems great some people are able to get it working, but we haven't put any dedicated effort into it so far.
is it planned to support it?
No, it isn't planned for any of the upcoming releases. We'd consider a PR if someone is willing to investigate this.
What way is then for now adviced to test NG2 apps?
you can take a look at my angular sample here: https://github.com/TobiasHennig/nativescript-toast/blob/master/samples/angular/app/tests/app.component.spec.ts
I've using TestBed: https://github.com/TobiasHennig/nativescript-toast/blob/master/samples/angular/app/tests/setup.js
you can check it for yourself, just clone the repo:
cd samples/angular
npm run clean && npm run build
npm run test // only on macOS
@hypery2k Does this still run for you?
I get:
Error: Not implemented! at NativeScriptDomAdapter.setGlobalVar
Using NativeScript 3, with Karma (and the rest of the setup like yours).
@hauthorn I just tried @hypery2k's config and I got the same error:
NativeScript / 10.3.1 (10.3.1; iPhone) LoginPage should init FAILED
Error: Not implemented! in file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js (line 993)
setGlobalVar@file:///app/tns_modules/nativescript-angular/dom-adapter.js:148:95 [ProxyZone]
_createNgProbe@file:///app/tns_modules/@angular/platform-browser/./bundles/platform-browser.umd.js:2383:26 [ProxyZone]
createInternal [ProxyZone]
BTW, does your console also have all the @file and in file lines? How do I disable them, they're just noise to me.
@hauthorn Check this out: https://github.com/NativeScript/nativescript-angular/issues/733. I was able to fix that setGlobalVar method by just writing over it. Not sure if this is the right thing to do...but TestBed works for me now.
Is TestBed supported in NativeScript? It seems like there are a bunch of potential workarounds that everyone tries, but without success. It is very important for my team to be able to use TestBed to initialize components which have numerous dependencies.
@Ahnert1 here you can find an example on how to configure testBed in NativeScript
Hey,
I have been working on trying to get TestBed configured properly in NativeScript for a month now and still haven't gotten it. The example provided is not sufficient as I have attempted to reproduce it and still face issues. I am unsure of what I am doing wrong.
Please checkout my Stack Overflow question if you have been able to get TestBed working in NativeScript I would very much appreciate it.
Most helpful comment
Is TestBed supported in NativeScript? It seems like there are a bunch of potential workarounds that everyone tries, but without success. It is very important for my team to be able to use TestBed to initialize components which have numerous dependencies.