小编Arj*_*ngh的帖子

错误:预期的 spy create 已被调用

我正在为具有异步服务组件编写 angular 7 的单元测试用例并收到此错误:

错误:预期的 spy create 已被调用一次。它被调用了 0 次。

这是我的组件:

export class RegistrationComponent implements OnInit {
    
   submitRegistrationForm() {
        if (this.profileForm.invalid) {
          this.validateAllFields(this.profileForm);
        } else {
          // send a http request to save this data
          this.guestUserService.create(this.profileForm.value).subscribe(
            result => {
              if (result) {
                console.log('result', result);
                this.router.navigate(['/login']);
              }
            },
            error => {
              console.log('error', error);
            });
        }
  }
Run Code Online (Sandbox Code Playgroud)

单元测试用例:

  describe('RegistrationComponent', () => {
      let component: RegistrationComponent;
      let fixture: ComponentFixture<RegistrationComponent>;
      let myService;
      let mySpy;
    
      beforeEach(async(() => {
    
        TestBed.configureTestingModule({
          declarations: [RegistrationComponent], …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing typescript karma-jasmine angular

0
推荐指数
2
解决办法
2万
查看次数