Skip to content

Instantly share code, notes, and snippets.

@fernandodof
Last active February 22, 2021 18:38
Show Gist options
  • Save fernandodof/781bdb9699421db0abb2db6d92ba5c53 to your computer and use it in GitHub Desktop.
Save fernandodof/781bdb9699421db0abb2db6d92ba5c53 to your computer and use it in GitHub Desktop.
const MOCK_PRICES = [50, 47, 53, 50, 49, 51, 52];
const MOCK_AVERAGE = 50.29;
global.fetch = jest.fn(() => Promise.resolve({
json: () => Promise.resolve(MOCK_PRICES)
}));
describe('Gold prices', () => {
let averagePrice;
describe('When the average price is called for 7 days', () => {
beforeEach(async () => {
averagePrice = await getPricesLastDays(7);
});
it('Then the correct average should be returned', () => {
expect(averagePrice).toEqual({ average: MOCK_AVERAGE });
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment