Skip to content

Commit

Permalink
test: mock getWaffleFlags api call to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Nov 8, 2024
1 parent e2fb999 commit 13eec2a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/library-authoring/LibraryAuthoringPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,6 @@ describe('<LibraryAuthoringPage />', () => {
});

render(<LibraryLayout />, { path, params: { libraryId: mockContentLibrary.libraryId } });
await waitFor(() => { expect(axiosMock.history.get.length).toBe(1); });
expect(screen.getByRole('alert')).toHaveTextContent('This page cannot be shown: Libraries v2 are disabled.');
expect(await screen.findByRole('alert')).toHaveTextContent('This page cannot be shown: Libraries v2 are disabled.');
});
});
5 changes: 5 additions & 0 deletions src/testUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {

import { ToastContext, type ToastContextData } from './generic/toast-context';
import initializeReduxStore from './store';
import { getApiWaffleFlagsUrl } from './data/api';

/** @deprecated Use React Query and/or regular React Context instead of redux */
let reduxStore: Store;
Expand Down Expand Up @@ -172,6 +173,10 @@ export function initializeMocks({ user = defaultUser, initialState = undefined }
});
axiosMock = new MockAdapter(getAuthenticatedHttpClient());

axiosMock
.onGet(getApiWaffleFlagsUrl())
.reply(200, {});

// Reset `mockToastContext` for this current test
mockToastContext = {
showToast: jest.fn(),
Expand Down

0 comments on commit 13eec2a

Please sign in to comment.