Profil

Beitrittsdatum: 18. Mai 2022

Info

softwareQ: Mock a function in Angular.js with Jasmine I'm trying to test a function that's using a service to perform a certain action. The



 

Microsoft SQL Server 2008 R2 Developer Edition Setup Free


Download


 





External links Official Microsoft SQL Server download page R2 Category:Microsoft server technology Category:Microsoft database softwareQ: Mock a function in Angular.js with Jasmine I'm trying to test a function that's using a service to perform a certain action. The service is an external dependency of my component which is in turn being tested. My Component: //... @Component({ selector:'my-component', templateUrl:'my-component.html', providers: [MyService] }) export class MyComponent implements OnInit { constructor(private _myService: MyService) { } ngOnInit(): void { this._myService.performAction() } } My Service: //... @Injectable() export class MyService { performAction(): void { //... } } My Jasmine test: it('should do a thing', () => { spyOn(MyService, 'performAction'); let service = new MyService(); expect(service.performAction).toHaveBeenCalled(); }); For some reason, I'm getting an error TypeError: Cannot read property 'performAction' of null I'm having trouble finding anything on Google, as most information seems to be about testing inner functions within a component, not something that's being used to execute a service. Any help would be appreciated. A: The problem is with your spyOn you are not injecting MyService in the constructor. You are actually injecting nothing. You should spyOn on the injector: spyOn(app.injector(), 'get').and.callThrough(); And then you can spy on MyService and get it injected to your spyOn mock. spyOn(MyService




ee43de4aa9

Microsoft SQL Server 2008 R2 Developer Edition Setup Free ((FREE))

Weitere Optionen