我正在嘗試對Angular 4.0.0組件進行測試,並使用了Mocha。我收到以下錯誤:摩卡測試角參考錯誤:未定義區域
var FakeAsyncTestZoneSpec = Zone['FakeAsyncTestZoneSpec'];
ReferenceError: Zone is not defined`
這裏是我的測試代碼:
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import {SocketService} from '../src/app/services/socket.service';
import 'mocha';
describe('BannerComponent (inline template)',() => {
let comp: SocketService;
let fixture: ComponentFixture<SocketService>;
let de: DebugElement;
let el: HTMLElement;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ SocketService ], // declare the test component
});
fixture = TestBed.createComponent(SocketService);
comp = fixture.componentInstance; // BannerComponent test instance
// query for the title <h1> by CSS element selector
de = fixture.debugElement.query(By.css('h1'));
el = de.nativeElement;
});
});
我一直在抓我的頭了一下,我已經通過每一個留言板和教程我能找到了,我的最佳偵察已經降臨,Zone.js沒有被實例化,不足以定義Zone
。我試圖在我的測試代碼中使用import 'zone.js'
,但它沒有任何影響。 有誰知道如何繞過或修復這個錯誤?
對不起,我詳細解答了我的答案。我希望現在很清楚。謝謝。 – HichamBI
現在看起來好多了,謝謝。 (不是我downvote順便說一句,我缺乏領域知識投票就此。) –
謝謝!我也欣賞線程。 :) – Rex