I am working on angular application in which I am writing unit test. I have one method in my component which is as follows
MyComponent - route(element) { this.myService.Name(element.Name); this.myService.Code(element.Code); this.router.navigate(["myPage"], { relativeTo: this.routes}); } MyService - Name(data) { this.name.next(data); } Code(data) { this.code.next(data); } private code = new BehaviorSubject(""); getCode = this.code.asObservable(); private name= new BehaviorSubject(""); getName = this.name.asObservable(); My unit test is as follows- it('route() function should be called', () => { component.route(mockData[0]); var spy = spyOn(component, "route").and.callThrough(); expect(spy).toBeDefined(); })
I am getting following error on running test case
TypeError: this.myService.Name is not a function
How can I resolve this?
https://stackoverflow.com/questions/67394282/testing-route-method-in-angular-unit-test May 05, 2021 at 10:06AM
没有评论:
发表评论