-
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.
Showing
5 changed files
with
2,759 additions
and
4,021 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
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,39 +1,39 @@ | ||
import mockAxios from 'jest-mock-axios' | ||
import axios from 'axios' | ||
import AxiosMockAdapter from 'axios-mock-adapter' | ||
|
||
jest.mock('axios', () => mockAxios) | ||
const Reaxios = require('./index').default | ||
|
||
const testUrl = 'https://foo.bar' | ||
const res = { data: { foo: 'bar' } } | ||
|
||
describe('Reaxios', () => { | ||
afterEach(() => mockAxios.reset()) | ||
const mock = new AxiosMockAdapter(axios) | ||
mock.onGet(testUrl).reply(200, res) | ||
mock.onPost(testUrl).reply(200, res) | ||
mock.onPut(testUrl).reply(200, res) | ||
mock.onDelete(testUrl).reply(200, res) | ||
|
||
describe('Reaxios', () => { | ||
it('should send GET request', async () => { | ||
const successFn = jest.fn() | ||
Reaxios.get(testUrl).then(successFn) | ||
mockAxios.mockResponseFor({ url: testUrl, method: 'GET' }, res) | ||
expect(successFn).toBeCalledWith(res.data) | ||
await Reaxios.get(testUrl).then(successFn) | ||
expect(successFn).toBeCalledWith(res) | ||
}) | ||
|
||
it('should send POST request', async () => { | ||
const successFn = jest.fn() | ||
Reaxios.post(testUrl).then(successFn) | ||
mockAxios.mockResponseFor({ url: testUrl, method: 'POST' }, res) | ||
expect(successFn).toBeCalledWith(res.data) | ||
await Reaxios.post(testUrl).then(successFn) | ||
expect(successFn).toBeCalledWith(res) | ||
}) | ||
|
||
it('should send PUT request', async () => { | ||
const successFn = jest.fn() | ||
Reaxios.put(testUrl).then(successFn) | ||
mockAxios.mockResponseFor({ url: testUrl, method: 'PUT' }, res) | ||
expect(successFn).toBeCalledWith(res.data) | ||
await Reaxios.put(testUrl).then(successFn) | ||
expect(successFn).toBeCalledWith(res) | ||
}) | ||
|
||
it('should send DELETE request', async () => { | ||
const successFn = jest.fn() | ||
Reaxios.delete(testUrl).then(successFn) | ||
mockAxios.mockResponseFor({ url: testUrl, method: 'DELETE' }, res) | ||
expect(successFn).toBeCalledWith(res.data) | ||
await Reaxios.delete(testUrl).then(successFn) | ||
expect(successFn).toBeCalledWith(res) | ||
}) | ||
}) |
Oops, something went wrong.