Reputation: 191
I've been working off the Angular tutorial https://angular.io/docs/ts/latest/guide/testing.html to build my first unit tests. I am able to get everything to work until I get to the TestBed example. When I add TestBed into the mix I get 'Uncaught ReferenceError: Zone is not defined'.
In my spec-bundle I zone declared and initialized the Testbed environment.
Spec-bundle
Error.stackTraceLimit = Infinity;
require('phantomjs-polyfill');
require('core-js/es6');
require('core-js/es7/reflect');
// Typescript emit helpers polyfill
require('ts-helpers');
// DO NOT REORDER: Dependency order needs to be strictly followed
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');
// RxJS
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]
});
});
});
Upvotes: 4
Views: 5343
Reputation: 760
I fixed this in my project by adding the following to my configuration. I am using Wallaby.js so to fix this issue I added the following line to my module.exports
{pattern: 'node_modules/zone.js/dist/zone.js', included: true, watched: true}
If you're using something like karma the same solution should apply.
Upvotes: 3