Questions tagged [spyon]

116 questions
0
votes
0 answers

Jest spyOn not working on React functional component that imports functions from another file

My jest.Spyon implementation seems pretty straight forward, but the spied function "does not" get called even though I see that it must be getting called. Function /** * Initialize the local & sync storage when the user first installs TabMerger. *…
lbragile
  • 7,549
  • 3
  • 27
  • 64
0
votes
1 answer

spyOn(Observable, 'fromEvent') throws error after upgrading to rxjs 6.5

getInactiveTimerTabSynchronizer() { return fromEvent(window, 'storage').pipe( filter((x: StorageEvent) => { return x.key === this.inactivityTabSynchronizerStorageKey; }), debounceTime(350)); } The above code has unit…
Ashutosh Singh
  • 269
  • 1
  • 2
  • 9
0
votes
1 answer

Modify mockImplementation results in SpyOn of jest

SpyOn is used to detect the parameters passed to an underlying function. In some cases we want to modify the result from the call-through and return that to the caller. How do we get the result of of the call-through in SpyOn before it is returned?…
David Dehghan
  • 22,159
  • 10
  • 107
  • 95
0
votes
0 answers

Jest.spyOn Illegal invocation

Currently, I have simple create react app with following code import React from "react"; export const readFilePromise = (file) => { return new Promise((resolve, reject) => { let reader = new FileReader(); reader.readAsDataURL(file); …
kenpeter
  • 7,404
  • 14
  • 64
  • 95
0
votes
1 answer

Why jest.spyOn does not find my component function?

Let's say I have this simple React (TypeScript) component: function Header(): JSX.Element { const initialItemIndex = useInitialItemIndex(); const [currentItem, setCurrentItem] = useState(initialItemIndex); function onChangeFunc(event:…
user636312
  • 143
  • 1
  • 4
  • 15
0
votes
2 answers

Jasmine unit test spyOn not working in callback function

I am using ag-grid and I need to write Jasmine unit test on a piece of code. This code calls our rest server using a class we called RestService and I want to use spyOn to mock those calls and responses. In other places in the code I use…
Justin Cross
  • 99
  • 11
0
votes
1 answer

spyOn response is coming back empty

it('should inject acaQQService and run getQQFormData', inject( [AcaQqService], (service: AcaQqService) => { const resp: QuickQuoteEntity = []; spyOn(service, 'getQQFormData').and.returnValue(of(resp)); …
ianhalfpenny
  • 147
  • 4
  • 15
0
votes
1 answer

Testing angular auth guard redirection

I have an Angular authenticated guard @Injectable({ providedIn: 'root' }) export class AuthenticatedGuard implements CanActivate, CanActivateChild { constructor(@Inject('Window') private window: Window, private readonly…
Chris Barr
  • 29,851
  • 23
  • 95
  • 135
0
votes
0 answers

Angular 7 mock and return value for window location search using jasmine

Unit test for angular 7 with Jasmine. I need to set the window.location.search value in Jasmine. I tried the following scenarios. window.location.search = '?param=part1' // It's not working. Browser reloaded or disconnected the unit test…
viji
  • 48
  • 1
  • 4
0
votes
1 answer

Unable to do angular unit testing due to method call present inside constructor

Unable to run angular unit test due to method present inside component constructor. export class AppComponent { name = 'Angular 4'; constructor(){ this.testMethod(); } testMethod(){ console.log("test method"); } …
1nteger
  • 839
  • 9
  • 15
0
votes
0 answers

using jasmine / spyOn to mock properties on an object

Is it possible to mock some properties on an object using Jasmine .spyOn()? Basically, imagine I have a Page object that has title, deliveryTime and status that I want to mock it such that I just have to set the title property title = 'test' ; the…
Denisa.B
  • 11
  • 1
  • 4
0
votes
2 answers

Spy a method having multiple arguments and a callback

I have a method like below service.myMethod(reqBody,true, false, false, (success) => { },(failure)=>{ }); I want to spy on this method and want to mock the success callback and I have tried the following const service =…
Swayangjit
  • 1,875
  • 2
  • 13
  • 22
0
votes
1 answer

How spy whether a function has been used or not with Jest unit testing for javascript?

When I try to set a spy on a imported function I get the following error msg TypeError: Cannot read property '_isMockFunction' of undefined I don't understand what it's wrong with this code Imported function is like below here export export function…
Donovant
  • 3,091
  • 8
  • 40
  • 68
0
votes
1 answer

spyon doesn't work with nested function in a non angularjs environment

I'm having a problem to spyon a function that is called from another function in my javascript module (no angularJS) this is the javascript module: var Utils = function () { function getFunction1(value1) { var value2 = getFunction2(); …
carlitos081
  • 151
  • 1
  • 13
0
votes
1 answer

Mocking a firebase calls using Jasmine

I'm looking to spyOn calls to the firebase database. I have a FireFunc file that wraps firebase calls. However, when I go to spyOn the check method, it returns the regular result. What's going on here? var FireFunc =…