I man having an issue in one of my test modules where I am getting the following error:
Failed: Can't resolve all parameters for CoreRequestClass: (?).
Error: Can't resolve all parameters for CoreRequestClass: (?).
Which is odd as as far as I can see I have included all required parameters to instantoate the module in the test.
Here is the service under test:
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;
}
}
And the test module:
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';
})));
});
});
I can't see why this spec won't be instantiating the module correctly. Can anyone see where i'm going wrong??
Thanks
Aucun commentaire:
Enregistrer un commentaire