data.json() is not a function error in Testing

2019-09-20 06:25发布

I am doing integration testing of a component.

public ngOnInit() {

    this.employeeService.getEmployees()
        .subscribe(data => {
            this.employees.next(data.json());
    });

  }

The above code is working fine when serving the project.

But during testing, it is throwing a error saying data.json() is not a function.

1条回答
Deceive 欺骗
2楼-- · 2019-09-20 07:06

You need to mock EmployeeService's getEmployees() method and return same response type object as the original.

查看更多
登录 后发表回答