Skip to content

Commit

Permalink
Fix flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
asanchezr committed Nov 27, 2024
1 parent 0110304 commit d6b3711
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions source/frontend/src/components/common/ApiVersionInfo.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import IApiVersion from '@/hooks/pims-api/interfaces/IApiVersion';
import { useApiHealth } from '@/hooks/pims-api/useApiHealth';
import { render, RenderOptions, waitForEffects } from '@/utils/test-utils';

import { ApiVersionInfo } from './ApiVersionInfo';
import { act, render, waitForEffects, RenderOptions } from '@/utils/test-utils';
import { useApiHealth } from '@/hooks/pims-api/useApiHealth';

const defaultVersion: IApiVersion = {
environment: 'test',
Expand Down
22 changes: 16 additions & 6 deletions source/frontend/src/components/layout/Footer/Footer.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { createMemoryHistory } from 'history';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';

import IApiVersion from '@/hooks/pims-api/interfaces/IApiVersion';
import { createMemoryHistory } from 'history';
import { RenderOptions, render } from '@/utils/test-utils';
import { RenderOptions, render, waitForEffects } from '@/utils/test-utils';

import Footer from './Footer';

const defaultVersion: IApiVersion = {
Expand All @@ -13,9 +15,7 @@ const defaultVersion: IApiVersion = {
dbVersion: '93.00',
};

const mockGetVersion = vi.fn(async () => {
return Promise.resolve({ data: defaultVersion });
});
const mockGetVersion = vi.fn();

const mockStore = configureMockStore([thunk]);
const history = createMemoryHistory();
Expand All @@ -39,8 +39,18 @@ vi.mock('@/hooks/pims-api/useApiHealth', () => ({
}));

describe('Footer', () => {
it('renders correctly', () => {
afterEach(() => {
vi.clearAllMocks();
});

beforeEach(() => {
import.meta.env.VITE_PACKAGE_VERSION = '11.1.1-93.999';
mockGetVersion.mockResolvedValue({ data: defaultVersion } as any);
});

it('renders correctly', async () => {
const { asFragment } = setup({});
await waitForEffects();
expect(asFragment()).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ exports[`Footer > renders correctly 1`] = `
class="version"
data-testid="version-tag"
>
v5.7.0-94.5
v11.1.1-93.999
</div>
<div
class="c2 c3"
Expand Down

0 comments on commit d6b3711

Please sign in to comment.