Questions tagged [spyon]

116 questions
1
vote
1 answer

How to Jest mock/spyOn a property of a class

I'm new to Jest so I apologise if my questioning doesn't read correctly, I'm unit testing a method on a vanilla JS class that has a reference to the class property 'this.original_params'. From reading the docs and many other Stackoverflow posts, I'm…
1
vote
1 answer

AddEventListener DOM event Jest testing

I have one Users vue component and I am trying to test mounted() with addEventListener. Users.vue ========= mounted(){ let viewPort = document.getElementById("Users-list"); ----> Here I am getting null for addEventListener. …
Sapthika
  • 31
  • 1
  • 4
1
vote
1 answer

Jasmine test case for PrimeNg Confirmation Service not working

I have a function which executes some operations in the "accept" call of PrimeNg Confirmation service. I tried to write a Unit test case for it as following: fit('submit preview config', fakeAsync(() => { addValues(); …
1
vote
1 answer

How to spy on a function called inside class object

I want to test if this.service.someMethod is called using jasmine spy. Source file: // src.ts import { Service } from 'some-package'; export class Component { service = new Service(); callMethod() { this.service.thatMethod(); …
Anant_Kumar
  • 764
  • 1
  • 7
  • 23
1
vote
2 answers

TypeError: Cannot read property 'subscribe' of undefined using spyOn

I am expecting an array to be undefined in a test of my Angular app. In order to do that, my test needs to first call a function of my tested component. Within that function, it subscribes to a service's function. Here is my test class. Including…
Drew13
  • 1,301
  • 5
  • 28
  • 50
1
vote
1 answer

Jest spyOn not called when deeper in call chain

I thought I'd be able to spyOn a function in my module but it doesn't register as being called even though it obviously was. Here's a boiled down sample.js: const func1 = () => { return func2(); }; const func2 = () => { return "func2…
Always Learning
  • 5,510
  • 2
  • 17
  • 34
1
vote
1 answer

How to spy on a function that is also referenced by a property

Given this code: function getAnimal(type, color) { console.log('blub'); // this is triggered when executing the test } this.getAnimal = getAnimal; and this testing code: describe('getAnimal()', function() { it('should get an animal based on…
GarfieldKlon
  • 11,170
  • 7
  • 31
  • 33
1
vote
1 answer

How to SpyOn function inside Function and return Fake value

This Question seems to be same but definitely not duplicate. In one of my function i am calling this.cordovaFile.readAsArrayBuffer(this.cordovaFile.dataDirectory, key) this cordovafile.readAsArrayBuffer() reads data from ipad File storage, but in…
Vikas Kalapur
  • 415
  • 4
  • 12
1
vote
0 answers

Jasmine spy setup for Promise wraps Observable

I am writing Angular a unit test case for a promise that wraps the observable call using Jasmine. I am not able to mock this promise in order to test it. Component ngOnInit(){ this.getOrder().then( () => { …
Developer
  • 487
  • 9
  • 28
1
vote
1 answer

How can we mock (spyOn) a method call in typescript test case?

save() { ..... this.saveSelectedOnes(); ..... } I have already written a test case for saveSelectedOnes() method. While writing test case for save method, how can we skip the saveSelectedOnes() method call?
Spring
  • 11
  • 3
1
vote
1 answer

What range of problems jest.fn() is intended to solve?

Maybe I am so badly dumb, but I cannot understand what jest.fn() does precisely and how it is used. I am new to testing and I've got basicly most functionality of jest, but jest.fn() makes me shaking. I tried to refer to docs, watch tutorials, but…
1
vote
2 answers

Angular Service becomes undefined when spyOn it

I have an Angular 1.6.6 application which I'm testing with Karma and Jasmine. Given this code from controller: $scope.undo = function () { return $scope.isUndoDisabled() || $scope.undoAction(); }; $scope.isUndoDisabled =…
Rafa Romero
  • 2,667
  • 5
  • 25
  • 51
1
vote
1 answer

Using Jasmine spyOn with a method of an object defined in a factory

In my angular JS application I have a mainController which takes in a userFactory as a parameter. The userFactory consists of an object called userService which in turn has a userDetails object and some methods including resetUserDetails. (see…
Sarah
  • 1,943
  • 2
  • 24
  • 39
1
vote
2 answers

Is using spyOn() without a method possible?

I'm new to jasmine and spies thing, hope you could point to the right direction. I have an event listener that i want to cover with unit test: var nextTurn = function() { continueButton.addEventListener("click",…
1
vote
1 answer

Angular unit Testing spyOn().and.callthrough doesn't call actual funciton

I am new in unit testing with Jasmine in Angular. I am currently testing a service that has a function called loadSomething(id) and I have added a console.info in it. MY SERVICE: function loadSomething(id) { console.info('this is a test…
user2998261
  • 11
  • 1
  • 1
  • 3