forked from OlympusDAO/olympus-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.unit.test.js
More file actions
executable file
·28 lines (23 loc) · 836 Bytes
/
index.unit.test.js
File metadata and controls
executable file
·28 lines (23 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import axios from "axios";
import { resetAllWhenMocks, when } from "jest-when";
import { getTokenPrice } from "./index";
beforeEach(() => {
resetAllWhenMocks(); //
});
test("getTokenPrice returns expected value", async () => {
const theSpiedMethod = jest.spyOn(axios, "get");
const resp = { data: { olympus: { usd: 300 } } };
when(theSpiedMethod).calledWith(expect.anything()).mockReturnValue(resp);
let price = await getTokenPrice("olympus");
expect(price).toEqual(300);
});
test("getTokenPrice returns 0 on remote call exceptions", async () => {
const theSpiedMethod = jest.spyOn(axios, "get");
when(theSpiedMethod)
.calledWith(expect.anything())
.mockImplementation(async () => {
throw Error("Remote API down");
});
let price = await getTokenPrice("olympus");
expect(price).toEqual(0);
});