Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用于启动确认服务的Jasmine测试用例不工作_Javascript_Angular_Jasmine_Karma Jasmine_Spyon - Fatal编程技术网

Javascript 用于启动确认服务的Jasmine测试用例不工作

Javascript 用于启动确认服务的Jasmine测试用例不工作,javascript,angular,jasmine,karma-jasmine,spyon,Javascript,Angular,Jasmine,Karma Jasmine,Spyon,我有一个函数,它在PrimeNg确认服务的“accept”调用中执行一些操作。我尝试为它编写一个单元测试用例,如下所示: fit('submit preview config', fakeAsync(() => { addValues(); component.submitConfig(); component.submitPreviewForm(); fixture.detectChanges(); const confirmationService =

我有一个函数,它在PrimeNg确认服务的“accept”调用中执行一些操作。我尝试为它编写一个单元测试用例,如下所示:

  fit('submit preview config', fakeAsync(() => {
   addValues();
   component.submitConfig();
   component.submitPreviewForm();
   fixture.detectChanges();
   const confirmationService = TestBed.get(ConfirmationService);
   tick(200);
   spyOn<any>(confirmationService, 'confirm').and.callFake((params: any) => {
     params.accept();
     httpMock.expectOne(baseUrl + '/api/project/addOrUpdate').flush(mockSubmitResponse);
     expect(component.successMsz).toBe(mockSubmitResponse.message);
   });
  flush();
}));
fit('submit preview config',fakeAsync(()=>{
addValues();
component.submitConfig();
submitPreviewForm();
fixture.detectChanges();
const confirmationService=TestBed.get(confirmationService);
勾选(200);

spyOn

您的操作顺序似乎有点混乱,在调用
submitPreviewform
之前,您需要
spy

试试这个:

fit('submit preview config', fakeAsync(() => {
   const confirmationService = TestBed.get(ConfirmationService); // grab a handle of confirmationService
   spyOn<any>(confirmationService, 'confirm').and.callFake((params: any) => {
     params.accept();
     httpMock.expectOne(baseUrl + '/api/project/addOrUpdate').flush(mockSubmitResponse);
     expect(component.successMsz).toBe(mockSubmitResponse.message);
   }); // spy on confirmationService.confirm now
   addValues();
   component.submitConfig();
   component.submitPreviewForm();
   fixture.detectChanges();
   tick(200);
   flush();
}));
fit('submit preview config',fakeAsync(()=>{
const confirmationService=TestBed.get(confirmationService);//获取confirmationService的句柄
spyOn(确认服务,'confirmationService')。和.callFake((参数:any)=>{
参数accept();
httpMock.expectOne(baseUrl+'/api/project/addOrUpdate').flush(mockSubmitResponse);
expect(component.successsz).toBe(mockSubmitResponse.message);
});//监视确认服务。立即确认
addValues();
component.submitConfig();
submitPreviewForm();
fixture.detectChanges();
勾选(200);
冲洗();
}));

您的操作顺序似乎有点混乱,在调用
submitPreviewform
之前,您需要
spy

试试这个:

fit('submit preview config', fakeAsync(() => {
   const confirmationService = TestBed.get(ConfirmationService); // grab a handle of confirmationService
   spyOn<any>(confirmationService, 'confirm').and.callFake((params: any) => {
     params.accept();
     httpMock.expectOne(baseUrl + '/api/project/addOrUpdate').flush(mockSubmitResponse);
     expect(component.successMsz).toBe(mockSubmitResponse.message);
   }); // spy on confirmationService.confirm now
   addValues();
   component.submitConfig();
   component.submitPreviewForm();
   fixture.detectChanges();
   tick(200);
   flush();
}));
fit('submit preview config',fakeAsync(()=>{
const confirmationService=TestBed.get(confirmationService);//获取confirmationService的句柄
spyOn(确认服务,'confirmationService')。和.callFake((参数:any)=>{
参数accept();
httpMock.expectOne(baseUrl+'/api/project/addOrUpdate').flush(mockSubmitResponse);
expect(component.successsz).toBe(mockSubmitResponse.message);
});//监视确认服务。立即确认
addValues();
component.submitConfig();
submitPreviewForm();
fixture.detectChanges();
勾选(200);
冲洗();
}));