错误:<spyOn>:getApplications()方法不存在Angular茉莉花单元测试

时间:2019-06-06 11:38:12

标签: angular unit-testing jasmine mocking

我正在尝试在Angular单元测试中模拟服务,但出现错误:

Error: <spyOn> : getApplications() method does not exist Angular unit test

我正在像这样使用茉莉和间谍

function configureapplicationServiceMock() {
applicationServiceMock = jasmine.createSpy('ApplicationServiceMock');
applicationServiceMock.application$ = Observable.of(Applications.ApplicationDummy);
const applicationInstellingen = new ApplicationInstellingen();
applicationInstellingen.emailEnabled = false;
applicationServiceMock.instellingen = applicationInstellingen;
spyOn(applicationServiceMock, 'getApplications');
}

像这样在beforeeach函数中调用此函数

beforeEach(() => {
    configureapplicationServiceMock();

    TestBed.configureTestingModule({
        imports: [ReactiveFormsModule, FormsModule, FileUploadModule, RouterModule.forRoot([])],
        declarations: [SendComponent, ResourcePipeStub],
        providers: [
            { provide: ResourcePipeStub, useClass: ResourcePipeStub },
            { provide: NotificationService, useFactory: () => notificationServiceMock },
            { provide: ApplicationService, useValue: applicationServiceMock }
        ],
        schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
    });
    fixture = TestBed.createComponent(SendComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
});

我尝试使用.and.returnValue()做类似spyOn的操作,但仍然无法正常工作。我什至尝试做这样的操作,例如applicationApplicationMock.getApplications = //函数已创建,但是没有任何效果。我在做什么错了?

0 个答案:

没有答案