我在我的一个测试模块中遇到问题,我收到以下错误:
Failed: Can't resolve all parameters for CoreRequestClass: (?).
Error: Can't resolve all parameters for CoreRequestClass: (?).
奇怪的是,据我所知,我已经包含了所有必需的参数来在测试中即时发布模块。
以下是受测试的服务:
import { Headers } from "@angular/http";
import { AuthenticationService } from "./authentication.service";
import { objectHelper } from "../helpers/objectHelper";
export class CoreRequestClass {
constructor(
protected _authenticationService: AuthenticationService
) {
}
createAuthorizationHeader(token:Boolean = false) {
let headers: Headers = new Headers();
if(token) {
headers.set('Authorization', 'Bearer ' + this._authenticationService.token);
}
return headers;
}
createURLVarString(urlVars: Object = {}) {
let urlString: string = '',
objLength = Object.keys(urlVars).length,
i = 1;
if(objLength !== 0) {
urlString += '?';
for(let [key, value] of objectHelper.loopThroughObject(urlVars)) {
urlString += key + '=' + value;
}
if(i !== objLength) {
urlString += '&';
i++;
}
}
return urlString;
}
}
测试模块:
import { inject, async, TestBed } from "@angular/core/testing";
import { Router } from "@angular/router";
import { CoreRequestClass } from "../../services/CoreRequestClass";
import { AuthenticationService } from "../../services/authentication.service";
import { BaseRequestOptions, HttpModule, Http } from "@angular/http";
import { MockBackend } from "@angular/http/testing";
describe('Core Request Class', () => {
let mockAuthenticateService = {
navigate: jasmine.createSpy('navigate')
};
let router = {
navigate: jasmine.createSpy('navigate')
};
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
CoreRequestClass,
AuthenticationService,
MockBackend,
BaseRequestOptions,
{
provide: Http,
useFactory: (backend, options) => new Http(backend, options),
deps: [MockBackend, BaseRequestOptions]
},
{ provide: Router, useValue: router },
{ provide: AuthenticationService, useValue: mockAuthenticateService}
],
imports: [
HttpModule
]
})
});
describe('createAuthorizationHeader', () => {
it('should return headers with a token set', async(inject([AuthenticationService], (authenticationService) => {
const token = 'token';
})));
});
});
我无法理解为什么此规范无法正确实例化模块。谁能看到我出错的地方?
由于