-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated dependencies, removed Babel and related files, improved comme…
…nts of API response validation against OpenAPI schema, added example of HTTP server mock with axios client
- Loading branch information
1 parent
302a0da
commit ba241e2
Showing
11 changed files
with
94 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules/ | |
.idea/ | ||
yarn.lock | ||
package-lock.json | ||
.npm/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,37 @@ | ||
const fetch = require('node-fetch') | ||
const axios = require('axios') | ||
const nock = require('nock') | ||
|
||
test('Mock HTTP server', async () => { | ||
// This is required to make nock correctly intercept axios requests. | ||
// https://github.com/axios/axios/issues/305 | ||
axios.defaults.adapter = require('axios/lib/adapters/http') | ||
|
||
describe('Mock HTTP server', () => { | ||
test('node-fetch client', async () => { | ||
// Mock HTTP server | ||
nock('http://hostname') | ||
.get('/path') | ||
.reply(200, 'text to return') | ||
|
||
// Request to HTTP server | ||
const response = await fetch('http://hostname/path') | ||
|
||
const body = await response.text() | ||
|
||
expect(response.status).toBe(200) | ||
expect(body).toBe('text to return') | ||
}) | ||
|
||
test('axios client', async () => { | ||
// Mock HTTP server | ||
nock('http://hostname') | ||
.get('/path') | ||
.reply(200, 'text to return') | ||
nock('http://hostname') | ||
.get('/path') | ||
.reply(200, 'text to return') | ||
|
||
// Request to HTTP server | ||
const response = await fetch('http://hostname/path') | ||
const body = await response.text() | ||
// Request to HTTP server | ||
const response = await axios.get('http://hostname/path') | ||
|
||
expect(response.status).toBe(200) | ||
expect(body).toBe('text to return') | ||
expect(response.status).toBe(200) | ||
expect(response.data).toBe('text to return') | ||
}) | ||
}) |
Oops, something went wrong.