我是karma和jasmin的整个TTD的新手,我试图在我的服务上运行测试,从我的数据库中提取数据,但我一直得到错误,说ReferenceError:找不到变量:在业力中的beforeEachProviders -test-shim.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();
});
});
});
答案 0 :(得分:1)
测试RC6 littel中的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() 你应该设置的地方提供:[]