我测试我的AuthenticationService
课时遇到问题,这个消息很混乱。我必须提供AuthenticationConfigService
,但在运行测试时我现在遇到此错误:jit__object_Object_26 is not a constructor
。有什么想法吗?
我的测试:
import { inject, TestBed } from "@angular/core/testing";
import { XHRBackend, Response, ResponseOptions } from "@angular/http";
import { MockBackend } from "@angular/http/testing";
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from "@angular/platform-browser-dynamic/testing";
import { HttpModule } from "@angular/http";
import { AuthenticationService } from "./authentication.service";
import { UserInformation } from "./user-information.model";
import { AuthenticationConfigService } from "./authentication-config.service";
describe("AuthenticationService", () => {
let _authenticationService;
let _authenticationConfigService;
beforeEach(() => {
_authenticationConfigService = jasmine.createSpyObj("AuthenticationConfigService", ["getConfiguration"]);
_authenticationConfigService.getConfiguration.and.returnValue(
jasmine.createSpyObj("Observable", ["subscribe"]));
TestBed.resetTestEnvironment();
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
TestBed.configureTestingModule({
imports: [HttpModule],
providers: [
AuthenticationService,
{ provide: AuthenticationConfigService, useClass: _authenticationConfigService },
{ provide: 'authenticationConfig', useValue: 'mock.json' }
]
});
});
beforeEach(inject([AuthenticationService], function(authenticationService) {
_authenticationService = authenticationService;
}));
describe("getUserInfo()", () => {
it("should return user information of authenticated user", function (done) {
_authenticationService.getUserInfo((userInformation: UserInformation) => {
/* *** Assert *** */
done();
});
});
});