Tests: Allow stubbing API

stable/1.0.x
Alex Gleason 2020-06-09 17:05:28 -05:00
rodzic 6810f8d0b6
commit 842f35ebc5
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 18 dodań i 6 usunięć

Wyświetl plik

@ -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;
};

Wyświetl plik

@ -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' },