1
我在http://plnkr.co/edit/ctjo8s8iUBPL9yUaVxP5?p=preview(通過對src/langaugesService.ts進行小改動從http://plnkr.co/edit/N3Acjuk7g9sPs35Rchjg?p=preview的工作示例改編)中說明了一個問題。我添加了構造函數。「服務測試中沒有字符串提供者」
export class LanguagesService {
private type: string;
constructor(type: string) {
this.type = type;
}
get() {
return ['en', 'es', 'fr'];
}
}
什麼我定義做修正下列測試(從SRC/languagesService.spec.ts)?
import {describe, it, expect, inject, beforeEach, beforeEachProviders} from 'angular2/testing';
import {LanguagesService} from './languagesService';
describe('Service: LanguagesService',() => {
let service;
beforeEachProviders(() => [
LanguagesService
]);
beforeEach(inject([LanguagesService], s => {
service = s;
}));
it('should return available languages',() => {
let languages = service.get();
expect(languages).toContain('en');
expect(languages).toContain('es');
expect(languages).toContain('fr');
expect(languages.length).toEqual(3);
});
})