Newer
Older
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { getGames } from "@/lib/igdb";
describe('games api', () => {
const mockGamesData = [
{
id: 1,
name: 'Game 1',
cover: {
image_id: 'cover_image_id_1',
url: 'cover_image_url_1'
},
},
{
id: 2,
name: 'Game 2',
cover: {
image_id: 'cover_image_id_2',
url: 'cover_image_url_2'
},
},
];
const mockAuthData = [
{
access_token: "1",
expires_in: 420,
token_type: 'bearer',
}
];
beforeAll(() => {
global.fetch = jest.fn()
.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve(mockAuthData),
})
.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve(mockGamesData),
});
});
test('get games', async () => {
const games = await getGames();
expect(games).toEqual(mockGamesData);
});
});