Skip to content

Commit

Permalink
Fix hanging test
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Baldwin committed Jan 19, 2024
1 parent f5e235d commit 9b3e06c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Expand Up @@ -47,7 +47,7 @@ jobs:
- run: python -m pip install tox
- run: python -m tox -e ${{ matrix.tox }}

lint_typecheck_webui:
lint_typecheck_test_webui:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
Expand Up @@ -47,7 +47,7 @@ const defaultProps = {
setSwarm: updateSwarm,
};

describe('SwarmForm', () => {
describe('SwarmUserClassPicker', () => {
beforeAll(() => server.listen());
afterEach(() => {
server.resetHandlers();
Expand Down Expand Up @@ -104,8 +104,11 @@ describe('SwarmForm', () => {
fireEvent.click(getByRole('button', { name: 'Save' }));
});

await waitFor(async () => {
await waitFor(() => {
expect(updateUserSettings).toHaveBeenCalled();

const submittedData = updateUserSettings.mock.calls[0][0];

if (submittedData) {
expect(submittedData).toEqual({ ...mockUsers.Example, userClassName: 'Example' });
}
Expand Down Expand Up @@ -152,8 +155,11 @@ describe('SwarmForm', () => {
fireEvent.click(getByRole('button', { name: 'Save' }));
});

await waitFor(async () => {
await waitFor(() => {
expect(updateUserSettings).toHaveBeenCalled();

const submittedData = updateUserSettings.mock.calls[0][0];

if (submittedData) {
expect(submittedData).toEqual({ ...updatedUser, userClassName: 'Example' });
expect(store.getState().swarm.users.Example).toEqual(updatedUser);
Expand Down
7 changes: 6 additions & 1 deletion locust/webui/src/test/setup.ts
@@ -1,5 +1,5 @@
import { cleanup } from '@testing-library/react';
import { afterEach, vi } from 'vitest';
import { afterAll, afterEach, vi } from 'vitest';

import { TEST_BASE_API } from 'test/constants';
import { swarmStateMock } from 'test/mocks/swarmState.mock';
Expand All @@ -25,3 +25,8 @@ vi.mock('echarts', async () => {

return { ...actual, init: (...args: any[]) => actual.init(...args, { width: 100, height: 100 }) };
});

afterAll(() => {
cleanup();
vi.clearAllMocks();
});

0 comments on commit 9b3e06c

Please sign in to comment.