question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not able to configure a module from TestBed.configureTestingModule

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
Ahnert1commented, 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.

1reaction
gsavchenkocommented, Jul 25, 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

What causes "Cannot configure the test module when the test ...
configureTestingModule inside a describe : Your project is on Angular 13+; You are using NgRx; You are using provideMockStore in your test. This...
Read more >
Improving Angular tests by enabling Angular testing module ...
If a component fixture has already been created, we must call TestBed.resetTestingModule before TestBed.configureTestingModule . Finally, it's ...
Read more >
Testing Dependency Injection • Angular - codecraft.tv
This is how we've injected dependencies so far in this section. The TestBed acts as a dummy Angular Module and we can configure...
Read more >
Application testing | Spectacular - GitHub Pages
To see what's possible with Angular's testbed, let's start by testing a simple synchronous ... No need to manually configure the Angular testing...
Read more >
Testing Components with children - Testing Angular
A unit test of HomeComponent does not render these children. ... We are using TestBed to configure a testing Module and to render...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found