sforkowany z mirror/soapbox
Tests: Allow stubbing API
rodzic
6810f8d0b6
commit
842f35ebc5
|
@ -1,10 +1,17 @@
|
|||
import MockAdapter from 'axios-mock-adapter';
|
||||
|
||||
const api = jest.requireActual('../api').default;
|
||||
let mocks = [];
|
||||
|
||||
export const __stub = func => mocks.push(func);
|
||||
|
||||
const setupMock = axios => {
|
||||
const mock = new MockAdapter(axios);
|
||||
mocks.map(func => func(mock));
|
||||
};
|
||||
|
||||
export default (...params) => {
|
||||
const axiosInstance = api(...params);
|
||||
const mock = new MockAdapter(axiosInstance);
|
||||
mock.onGet('/instance/about/index.html').reply(200, '<h1>Hello world</h1>');
|
||||
return axiosInstance;
|
||||
const axios = api(...params);
|
||||
setupMock(axios);
|
||||
return axios;
|
||||
};
|
||||
|
|
|
@ -6,12 +6,17 @@ import {
|
|||
fetchAboutPage,
|
||||
} from '../about';
|
||||
import { Map as ImmutableMap } from 'immutable';
|
||||
import { __stub as stubApi } from 'soapbox/api';
|
||||
|
||||
const middlewares = [thunk];
|
||||
const mockStore = configureMockStore(middlewares);
|
||||
|
||||
describe('About actions', () => {
|
||||
it('creates FETCH_ABOUT_PAGE_SUCCESS when fetching about page has been done', () => {
|
||||
describe('fetchAboutPage()', () => {
|
||||
beforeAll(() => stubApi(mock => {
|
||||
mock.onGet('/instance/about/index.html').reply(200, '<h1>Hello world</h1>');
|
||||
}));
|
||||
|
||||
it('creates the expected actions', () => {
|
||||
const expectedActions = [
|
||||
{ type: FETCH_ABOUT_PAGE_REQUEST, slug: 'index' },
|
||||
{ type: FETCH_ABOUT_PAGE_SUCCESS, slug: 'index' },
|
||||
|
|
Ładowanie…
Reference in New Issue