Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

zone is not defined ( Uncaught ReferenceError: Zone is not defined ) #776

Closed
AnkitaChavan opened this issue May 11, 2017 · 9 comments
Closed

Comments

@AnkitaChavan
Copy link

No description provided.

@JiaLiPassion
Copy link
Collaborator

@AnkitaChavan , any detail?

@AnkitaChavan
Copy link
Author

@JiaLiPassion

This is my login.spec.ts

import { Router, ActivatedRoute } from '@angular/router';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { CommonModule } from  '@angular/common';
import { ComponentFixture, TestBed } from '@angular/core/testing';

import {LoginComponent} from './login.component';
import { LoginUser } from './loginUser.model'
import { UserService } from './user.service';
import { LoaderService } from '../shared/loader.service';
import 'rxjs/add/operator/toPromise';





describe('Login Component Test', () => {
 
  let comp:    LoginComponent;
  let fixture: ComponentFixture<LoginComponent>; 

  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [ LoginComponent ], // declare the test component
    });
 
  fixture = TestBed.createComponent(LoginComponent);

  comp = fixture.componentInstance; // BannerComponent test instance

  });

   it("should call login function", function ()  {

      let  loginObjValue = {
        password:"pas",
        userName:"abc"
      };
      //fixture.detectChanges();
      comp.login(loginObjValue);
      
   });

after ng test, It shows following error :

Uncaught ReferenceError: Zone is not defined
at Object. (testing.es5.js:281)
at Object.443 (testing.es5.js:954)
at webpack_require (bootstrap cb57066…:47)
at Object.444 (login.spec.ts:7)
at webpack_require (bootstrap cb57066…:47)
at bootstrap cb57066…:139
at bootstrap cb57066…:139

Please help.

@AnkitaChavan AnkitaChavan changed the title zone is not defined zone is not defined ( Uncaught ReferenceError: Zone is not defined ) May 12, 2017
@JiaLiPassion
Copy link
Collaborator

@AnkitaChavan , you can try add this line before describe

declare let Zone: any;

@JiaLiPassion
Copy link
Collaborator

@AnkitaChavan , can you post your repo? maybe you didn't load zone.js to your polyfill

@JiaLiPassion
Copy link
Collaborator

@AnkitaChavan , yes, it seems you didn't load zone.js in karma.conf, I don't know your project structure, but you may reference the angular quickstart project
https://github.com/angular/quickstart/blob/master/karma.conf.js#L42

@AnkitaChavan
Copy link
Author

@JiaLiPassion ,Still receiving same error..

@JiaLiPassion
Copy link
Collaborator

@AnkitaChavan , could you provide your repo?

@DerekB20
Copy link

DerekB20 commented Jun 2, 2017

I had the same issue. It was because I had moved some of the files (such as karma.conf) to it's own folder. To fix, I updated the 'base' config property as follows...

module.exports = function (config) {
config.set({
basePath: '../',
frameworks: ['jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular/cli/plugins/karma')
],

i.e. changed this from '' to '../'

It was then able to locate the zone.js files.

@JiaLiPassion
Copy link
Collaborator

@DerekB20 , thank you for the information.

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

No branches or pull requests

3 participants