NativeScript / NativeScript/nativescript-cli

tns test fails with error "ReferenceError: Can't find variable: Zone"

Open
#3,303 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

to-be-checked unit testing
Dominant language
JavaScript
Stars
1.1k
Forks
204
Avg merge
1d 9h
Merged PRs (30d)
8

Description

Tell us about the problem

Please, ensure your title is less than 63 characters long and starts with a capital
letter.

Which platform(s) does your issue occur on?

iOS, Android

Please provide the following version numbers that your issue occurs with:
  • CLI: (run tns --version to fetch it)
    3.4.0

  • Cross-platform modules: (check the 'version' attribute in the
    node_modules/tns-core-modules/package.json file in your project)
    3.3.0

  • Runtime(s): (look for the "tns-android" and "tns-ios" properties in the
    package.json file of your project)
    3.0.0

Please tell us how to recreate the issue in as much detail as possible.
  • Build a service that requires injection of TranslateService (from ng-translate)
  • Inject that service in beforeEach() of a test suite.
Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.

error.service.test.ts

'use strict';

import {ErrorService} from '../services/error.service';
import {inject} from "@angular/core/testing";

declare let assert: Chai.AssertStatic;

describe("ErrorService tests", () => {

    let service = null;

    beforeEach((done) => {
        inject([ErrorService], (injectService: ErrorService) => {
            service = injectService;
            done();
        });
    });

    it("Service exists", (done) => {
        assert.exists(service);
        done();
    });

});

error.service.ts

import { Injectable } from "@angular/core";
import { TranslateService } from "ng2-translate";

@Injectable()
export class ErrorService {

    constructor(private i18n: TranslateService) {
    }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported tns test failure using the versions listed for the CLI, modules, and runtimes. Read error.service.test.ts and error.service.ts, focusing on the Angular testing injection in beforeEach(). Done means the service test runs on both iOS and Android without the ReferenceError about Zone.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, javascript
Domain
cli, mobile, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.