samedi 5 décembre 2020

Jest : Mocking chained function

I'd like to test my code written in JS but I don't know how I can do that. I have a function which call another which call another function like that :

functionA => functionB => functionC

And I'd like to keep the original behavior and test like that :

functionA => mockFunctionB => mockFunctionC
jest.spyOn(functionC, 'sendEmail').mockImplementation(() => {'Done'});
jest.spyOn(functionB, 'evaluateBeforeSend');
const result = jest.spyOn(functionA, 'create');

expect(result).toEqual(XX);

I'd like to mock functionB and functionC in way to call only functionA and assert results coming from functionA. Thanks

Aucun commentaire:

Enregistrer un commentaire