kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Tests: mock staticClient correctly
rodzic
ea26e86a94
commit
6e27116aa4
|
@ -1,6 +1,7 @@
|
||||||
/node_modules/**
|
/node_modules/**
|
||||||
/static/**
|
/static/**
|
||||||
/static-test/**
|
/static-test/**
|
||||||
|
/public/**
|
||||||
/tmp/**
|
/tmp/**
|
||||||
/coverage/**
|
/coverage/**
|
||||||
!.eslintrc.js
|
!.eslintrc.js
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import MockAdapter from 'axios-mock-adapter';
|
import MockAdapter from 'axios-mock-adapter';
|
||||||
|
|
||||||
const api = jest.requireActual('../api').default;
|
const api = jest.requireActual('../api');
|
||||||
let mocks = [];
|
let mocks = [];
|
||||||
|
|
||||||
export const __stub = func => mocks.push(func);
|
export const __stub = func => mocks.push(func);
|
||||||
|
@ -11,8 +11,10 @@ const setupMock = axios => {
|
||||||
mocks.map(func => func(mock));
|
mocks.map(func => func(mock));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const staticClient = api.staticClient;
|
||||||
|
|
||||||
export default (...params) => {
|
export default (...params) => {
|
||||||
const axios = api(...params);
|
const axios = api.default(...params);
|
||||||
setupMock(axios);
|
setupMock(axios);
|
||||||
return axios;
|
return axios;
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,15 +5,17 @@ import {
|
||||||
fetchAboutPage,
|
fetchAboutPage,
|
||||||
} from '../about';
|
} from '../about';
|
||||||
import { Map as ImmutableMap } from 'immutable';
|
import { Map as ImmutableMap } from 'immutable';
|
||||||
import { __stub as stubApi } from 'soapbox/api';
|
import MockAdapter from 'axios-mock-adapter';
|
||||||
|
import { staticClient } from 'soapbox/api';
|
||||||
import { mockStore } from 'soapbox/test_helpers';
|
import { mockStore } from 'soapbox/test_helpers';
|
||||||
|
|
||||||
describe('fetchAboutPage()', () => {
|
describe('fetchAboutPage()', () => {
|
||||||
it('creates the expected actions on success', () => {
|
it('creates the expected actions on success', () => {
|
||||||
|
|
||||||
stubApi(mock => {
|
const mock = new MockAdapter(staticClient);
|
||||||
mock.onGet('/instance/about/index.html').reply(200, '<h1>Hello world</h1>');
|
|
||||||
});
|
mock.onGet('/instance/about/index.html')
|
||||||
|
.reply(200, '<h1>Hello world</h1>');
|
||||||
|
|
||||||
const expectedActions = [
|
const expectedActions = [
|
||||||
{ type: FETCH_ABOUT_PAGE_REQUEST, slug: 'index' },
|
{ type: FETCH_ABOUT_PAGE_REQUEST, slug: 'index' },
|
||||||
|
|
Ładowanie…
Reference in New Issue