2

我在测试我的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();
        });

    });
});
4

0 回答 0