I've got a set of data coming from from the same API call. Each call has a different data as specified in endpoint parameters.
reportData = new Promise((resolve, reject) => {
Promise.all([
fetchBudgetTableReport(reportParams.datetype,
reportParams.bgid,
reportParams.startdate,
reportParams.enddate,
'receivable'),
fetchBudgetTableReport(reportParams.datetype,
reportParams.bgid,
reportParams.startdate,
reportParams.enddate,
'payable'),
])
How can I mock those two calls in unit tests using Jest.
For the single call it's obvious and this is what I'm always doing:
jest.mock('../Reports', () => ({
fetchBudgetTableReport: jest.fn().mockReturnValue(Promise.resolve(data1)),
}));
Or if I need to mock it for a single test I go with
fetchBudgetTableReport.mockReturnValue(Promise.resolve(data2));
But how to make it for the same endpoint to get two different set of data like in my Promise.all example?
This solution obviously not working:
fetchBudgetTableReport.mockReturnValue(Promise.resolve(data1));
fetchBudgetTableReport.mockReturnValue(Promise.resolve(data2));