Skip to content

Not able to configure a module from TestBed.configureTestingModule #479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tsonevn opened this issue Sep 29, 2016 · 15 comments
Open

Not able to configure a module from TestBed.configureTestingModule #479

tsonevn opened this issue Sep 29, 2016 · 15 comments
Labels

Comments

@tsonevn
Copy link
Contributor

tsonevn commented Sep 29, 2016

From @ignaciolarranaga on September 28, 2016 21:3

Please, provide the details below:

Tell us about the problem

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)

Which platform(s) does your issue occur on?

iOS

Please provide the following version numbers that your issue occurs with:

  • CLI: 2.3.0
  • Cross-platform modules:
    tns-core-modules: 2.3.0
  • Runtime(s): ios 2.3.0

Please tell us how to recreate the issue in as much detail as possible.

Just try to configure a test module

Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.

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

@ignaciolarranaga
Copy link

@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!

@hypery2k
Copy link
Contributor

hypery2k commented Oct 6, 2016

related to #478

@hypery2k
Copy link
Contributor

hypery2k commented Oct 6, 2016

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

@nakedcity
Copy link

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

@hdeshev hdeshev mentioned this issue Dec 9, 2016
@hdeshev
Copy link
Contributor

hdeshev commented Dec 9, 2016

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.

@nakedcity
Copy link

is it planned to support it?

@hdeshev
Copy link
Contributor

hdeshev commented Dec 9, 2016

No, it isn't planned for any of the upcoming releases. We'd consider a PR if someone is willing to investigate this.

@nakedcity
Copy link

What way is then for now adviced to test NG2 apps?

@hypery2k
Copy link
Contributor

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

@hauthorn
Copy link

@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).

@kamok
Copy link

kamok commented Jul 24, 2017

@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.

@kamok
Copy link

kamok commented Jul 24, 2017

@hauthorn Check this out: #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.

@Ahnert1
Copy link

Ahnert1 commented Mar 29, 2019

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.

@NickIliev
Copy link

@Ahnert1 here you can find an example on how to configure testBed in NativeScript

@gsavchenko
Copy link

gsavchenko commented Jul 24, 2019

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.

https://stackoverflow.com/questions/57186925/how-to-implement-unit-tests-in-nativescript-using-testbed-and-jasmine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants