-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.test.js
35 lines (32 loc) · 1.11 KB
/
api.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
/* eslint-disable no-console */
const api = require('./api')
const testApi = api({ https: false, host: 'localhost', port: '3210', path: '/api/test/apitest' })
describe('api calls works as expected', () => {
it('performs a successful get request when calling getText', done => {
testApi.getText(data => {
expect(data).toBe('text/plain')
done()
})
})
it('performs a successful get request when calling getJson', done => {
testApi.getJson(data => {
expect(data.type).toBe('application/json')
done()
})
})
it('performs a successful post request when calling postJson', done => {
testApi.postJson('{ "data": "test" }', data => {
expect(data).toMatchObject({ data: 'test' })
done()
})
})
// Test promise based functions
it('performs a successful get request when calling promisedGetText', async () => {
const data = await testApi.promisedGetText()
expect(data).toBe('text/plain')
})
it('performs a successful get request when calling promisedApiCall', async () => {
const data = await testApi.promisedApiCall()
expect(data).toBe('*/*')
})
})