I worked on the Angular tutorial https://angular.io/docs/ts/latest/guide/testing.html to create my first unit tests. I can make everything work until I get the TestBed example. When I add TestBed to the mix, I get the message "Uncaught ReferenceError: Zone is not defined".
In my spectral package zone, I declared and initialized the Testbed environment.
Spec bundle
Error.stackTraceLimit = Infinity;
require('phantomjs-polyfill');
require('core-js/es6');
require('core-js/es7/reflect');
require('ts-helpers');
require('zone.js/dist/zone');
require('zone.js/dist/long-stack-trace-zone');
require('zone.js/dist/async-test');
require('zone.js/dist/fake-async-test');
require('zone.js/dist/sync-test');
require('zone.js/dist/proxy');
require('zone.js/dist/jasmine-patch');
require('rxjs/Rx');
var testing = require('@angular/core/testing');
var browser = require('@angular/platform-browser-dynamic/testing');
testing.TestBed.initTestEnvironment(
browser.BrowserDynamicTestingModule,
browser.platformBrowserDynamicTesting()
);
Object.assign(global, testing);
window.__karma__ && require('./karma-require');
Test file
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SomeComponent } from './some.component';
let fixture: ComponentFixture<SomeComponent>;
describe('Orders Component', () => {
let ordersComponentStub: SomeComponent;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [SomeComponent]
});
});
});
source
share