tl;dr:
- I use Jasmine;
- I want to test
aaa
function which calledbbb
from the same module; - I want to spy on
bbb
, but eventuallyaaa
called the originalbbb
function, not a spy;
How can I force aaa
to call the spy?
The Module:
export function aaa() {
return bbb();
}
export function bbb() {
return 222;
}
The test:
import * as util from 'my-module';
describe('aaa test', () => {
let bbbSpy: Spy;
beforeEach(() => {
bbbSpy = spyOn(util, 'bbb');
});
it('should return SPYED', () => {
bbbSpy.and.returnValue('SPYED!!');
const result = util.aaa();
expect(result).toEqual('SPYED!!'); // Doesn't work - still 222
});
});
So, basically that doesn't work. Can anyone help me please?
P.S. I don't want to change the module's code, because in that case I'll have to change tons of code in the project. I need a general solution for tests.