From f71f7e4dbd20704c7c15bad9ab808b6074656585 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 9 Jun 2020 17:16:22 -0500 Subject: [PATCH] Tests: Clear API mocks between each test --- app/soapbox/__mocks__/api.js | 1 + app/soapbox/actions/__tests__/about-test.js | 2 +- app/soapbox/test_setup.js | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/soapbox/__mocks__/api.js b/app/soapbox/__mocks__/api.js index b59b546ab..839cbfa70 100644 --- a/app/soapbox/__mocks__/api.js +++ b/app/soapbox/__mocks__/api.js @@ -4,6 +4,7 @@ const api = jest.requireActual('../api').default; let mocks = []; export const __stub = func => mocks.push(func); +export const __clear = () => mocks = []; const setupMock = axios => { const mock = new MockAdapter(axios); diff --git a/app/soapbox/actions/__tests__/about-test.js b/app/soapbox/actions/__tests__/about-test.js index a07dc2fda..c0caf5e2c 100644 --- a/app/soapbox/actions/__tests__/about-test.js +++ b/app/soapbox/actions/__tests__/about-test.js @@ -12,7 +12,7 @@ const middlewares = [thunk]; const mockStore = configureMockStore(middlewares); describe('fetchAboutPage()', () => { - beforeAll(() => stubApi(mock => { + beforeEach(() => stubApi(mock => { mock.onGet('/instance/about/index.html').reply(200, '

Hello world

'); })); diff --git a/app/soapbox/test_setup.js b/app/soapbox/test_setup.js index 297c64d7d..8fa14ad2f 100644 --- a/app/soapbox/test_setup.js +++ b/app/soapbox/test_setup.js @@ -2,8 +2,10 @@ import { configure } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; +import { __clear as clearApiMocks } from 'soapbox/api'; const adapter = new Adapter(); configure({ adapter }); jest.mock('soapbox/api'); +afterEach(() => clearApiMocks());