Jasmine spyOn with specific arguments
You can use callFake: spyOn($cookieStore,’get’).and.callFake(function(arg) { if (arg === ‘someValue’){ return ‘someabc’; } else if(arg === ‘anotherValue’) { return ‘anotherabc’; } });
You can use callFake: spyOn($cookieStore,’get’).and.callFake(function(arg) { if (arg === ‘someValue’){ return ‘someabc’; } else if(arg === ‘anotherValue’) { return ‘anotherabc’; } });
Cannot agree using jest.mock() instead of spyOn() (here) is a good solution. With that approach you have to mock all functions once at the top of your spec file. But some of the test cases might need a different setup or stay real. Anyway, I want to continue use spyOn(). A better way is to … Read more
This one was interesting. Issue Babel generates properties with only get defined for re-exported functions. utils/serverRequests/index.ts re-exports functions from other modules so an error is thrown when jest.spyOn is used to spy on the re-exported functions. Details Given this code re-exporting everything from lib: export * from ‘./lib’; …Babel produces this: ‘use strict’; Object.defineProperty(exports, “__esModule”, … Read more