我新来了整个TTD与karma和jasmin,我试图运行一个测试我的服务,从我的DB拉数据,但我不断得到错误说ReferenceError:找不到变量:beforeEachProviders在karma-test- shimm .js这是我的测试下面..
import { TracksServices } from './tracks.services.ts';
describe('Service: TracksServices', () => {
let service;
//setup
beforeEach(() => TestBed.configureTestingModule({
imports: [ TracksModule, HttpModule ],
providers: [
TracksServices
],
}));
it('get 4 featured images', done => {
service.featured(1, 4).subscribe(x => {
expect(x).toContain(track);
expect(x.length).toEqual(4);
done();
});
});
});
在RC6中测试API有一点变化。
例如angular2-webpack-starter.
import { inject, TestBed } from '@angular/core/testing';
// Load the implementations that should be tested
import { App } from './app.component';
import { AppState } from './app.service';
describe('App', () => {
// provide our implementations or mocks to the dependency injector
beforeEach(() => TestBed.configureTestingModule({
providers: [
AppState,
App
]
}));
it('should have a url', inject([ App ], (app: App) => {
expect(app.url).toEqual('https://twitter.com/AngularClass');
}));
});
beforeEachProvider被移除,现在使用TestBed.configureTestingModule()[]