/
fetch-git-mob-contributors.test.js
53 lines (43 loc) · 1.47 KB
/
fetch-git-mob-contributors.test.js
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
49
50
51
52
53
import React from 'react';
import { render, Simulate, wait } from 'react-testing-library'
import 'dom-testing-library/extend-expect';
import { FetchGitMobContributors } from './fetch-git-mob-contributors';
beforeAll(function () {
global.fetch = jest.fn().mockImplementation(async () => {
return {
ok: true,
json: function () {
return [
{
"total": 59,
"author": {
"login": "rkotze",
"id": 1234,
"avatar_url": "https://avatars2.githubusercontent.com/u/1234?v=4"
}
},
{
"total": 122,
"author": {
"login": "dideler",
"id": 4567,
"avatar_url": "https://avatars2.githubusercontent.com/u/4567?v=4"
}
}
]
}
};
});
});
test('Click button to fetch git mob contributors and display in a list', async () => {
const { getByText, getAllByTestId, getByTestId, container } = render(<FetchGitMobContributors />);
Simulate.click(getByText('Fetch Git Mob contributors'));
await wait(() => getByTestId('contributor'));
expect(fetch).toHaveBeenCalledTimes(1);
const contributors = getAllByTestId('contributor');
expect(contributors).toHaveLength(2);
expect(contributors[0]).toHaveTextContent('rkotze')
expect(contributors[0]).toHaveTextContent('59');
expect(contributors[1]).toHaveTextContent('dideler')
expect(contributors[1]).toHaveTextContent('122');
});