Skip to content

Commit 6aa48ec

Browse files
committed
🚧 Add tests for each req. method
1 parent 43a24cb commit 6aa48ec

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
"typedoc": "^0.21.0",
6363
"typedoc-github-wiki-theme": "^0.4.1",
6464
"typedoc-plugin-markdown": "^3.10.0",
65-
"typescript": "4.x"
65+
"typescript": "4.x",
66+
"whatwg-fetch": "^3.6.2"
6667
},
6768
"husky": {
6869
"hooks": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import 'whatwg-fetch';
2+
import { generatorToPromise as toPromise } from '../../makeRequest';
3+
import { Antonio } from '../Antonio';
4+
5+
describe('Antonio class', () => {
6+
let api: Antonio;
7+
8+
beforeEach(() => {
9+
api = new Antonio({
10+
baseURL: 'https://jsonplaceholder.typicode.com/',
11+
});
12+
});
13+
14+
afterEach(() => {
15+
api.destroy();
16+
});
17+
18+
it('fetch users', async () => {
19+
const { data, response, request } = await toPromise(api.get('/users'));
20+
21+
expect(data).toBeInstanceOf(Array);
22+
expect(response).toBeInstanceOf(Response);
23+
expect(request).toBeInstanceOf(Request);
24+
});
25+
26+
// TODO:
27+
it.skip('create a user', async () => {
28+
interface User {
29+
name: string;
30+
}
31+
const user: User = {
32+
name: 'Alois',
33+
};
34+
const { data } = await toPromise(api.post('/users', user));
35+
36+
expect(data).toContain(user);
37+
});
38+
});

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -11040,6 +11040,11 @@ whatwg-encoding@^1.0.5:
1104011040
dependencies:
1104111041
iconv-lite "0.4.24"
1104211042

11043+
whatwg-fetch@^3.6.2:
11044+
version "3.6.2"
11045+
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.6.2.tgz#dced24f37f2624ed0281725d51d0e2e3fe677f8c"
11046+
integrity sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==
11047+
1104311048
whatwg-mimetype@^2.3.0:
1104411049
version "2.3.0"
1104511050
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf"

0 commit comments

Comments
 (0)