【发布时间】:2019-04-26 16:38:37
【问题描述】:
我正在尝试使用注入设置单元测试。但我不确定如何设置参数。
正在测试的类(auth.service.ts)的构造函数是:
constructor(private http : HttpClient, private token: TokenStorage) {}
单元测试类 (auth.service.spec.ts)
import { TestBed, inject } from '@angular/core/testing';
import { AuthService } from './auth.service';
import { HttpClient, HttpHandler, HttpClientModule } from '@angular/common/http';
import { TokenStorage } from './token.storage';
describe('AuthService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [AuthService, HttpClient, HttpHandler, HttpClientModule, TokenStorage]
});
});
it('should be created', inject([AuthService], (service: AuthService) => {
expect(service).toBeTruthy();
}));
});
【问题讨论】:
-
标签angular 用于angular.io (2+),标签angularjs 用于angularjs.org (1x)。使用正确的标签有助于让开发人员了解您的问题,从而更好地回答您的问题。
标签: angular unit-testing karma-jasmine inject