From 6e27116aa4bc3a59d798ba3f932732466a5f8a35 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 5 Sep 2021 14:07:42 -0500 Subject: [PATCH] Tests: mock staticClient correctly --- .eslintignore | 1 + app/soapbox/__mocks__/api.js | 6 ++++-- app/soapbox/actions/__tests__/about-test.js | 10 ++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.eslintignore b/.eslintignore index 46b769557..fe31218da 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,6 +1,7 @@ /node_modules/** /static/** /static-test/** +/public/** /tmp/** /coverage/** !.eslintrc.js diff --git a/app/soapbox/__mocks__/api.js b/app/soapbox/__mocks__/api.js index 839cbfa70..6ecb81c41 100644 --- a/app/soapbox/__mocks__/api.js +++ b/app/soapbox/__mocks__/api.js @@ -1,6 +1,6 @@ import MockAdapter from 'axios-mock-adapter'; -const api = jest.requireActual('../api').default; +const api = jest.requireActual('../api'); let mocks = []; export const __stub = func => mocks.push(func); @@ -11,8 +11,10 @@ const setupMock = axios => { mocks.map(func => func(mock)); }; +export const staticClient = api.staticClient; + export default (...params) => { - const axios = api(...params); + const axios = api.default(...params); setupMock(axios); return axios; }; diff --git a/app/soapbox/actions/__tests__/about-test.js b/app/soapbox/actions/__tests__/about-test.js index 19fa9bcad..f6ce02099 100644 --- a/app/soapbox/actions/__tests__/about-test.js +++ b/app/soapbox/actions/__tests__/about-test.js @@ -5,15 +5,17 @@ import { fetchAboutPage, } from '../about'; 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'; describe('fetchAboutPage()', () => { it('creates the expected actions on success', () => { - stubApi(mock => { - mock.onGet('/instance/about/index.html').reply(200, '

Hello world

'); - }); + const mock = new MockAdapter(staticClient); + + mock.onGet('/instance/about/index.html') + .reply(200, '

Hello world

'); const expectedActions = [ { type: FETCH_ABOUT_PAGE_REQUEST, slug: 'index' },