Skip to content

Commit 0f30768

Browse files
improve tests for «reload» and page status handling
ensure «reload» in tests is awaited for proper async behavior reset mocks and refine data source context to prevent false positives add explicit checks that «search» is not called during data source fetching improve test reliability and accuracy around loading state
1 parent 2a6356b commit 0f30768

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

public/components/monitoring/__tests__/use_monitoring.test.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ describe('useMonitoring', () => {
161161

162162
await waitFor(() => expect(Model.prototype.search).toHaveBeenCalledTimes(1));
163163

164-
act(() => {
165-
result.current.reload();
164+
await act(async () => {
165+
await result.current.reload();
166166
});
167167
await waitFor(() => expect(Model.prototype.search).toHaveBeenCalledTimes(2));
168168
});
@@ -724,12 +724,22 @@ describe('useMonitoring.pageStatus', () => {
724724
});
725725

726726
it('should return "loading" and not call model search when data source id is fetching', async () => {
727+
// Reset any prior calls from previous tests to avoid false positives
728+
jest.clearAllMocks();
727729
const {
728730
renderHookResult: { result, waitFor },
729-
} = setup();
731+
} = setup({
732+
initDataSourceContextValue: {
733+
dataSourceEnabled: true,
734+
selectedDataSourceOption: null,
735+
},
736+
});
730737

731738
await waitFor(() => {
732739
expect(result.current.pageStatus).toBe('loading');
733740
});
741+
await waitFor(() => {
742+
expect(Model.prototype.search).not.toHaveBeenCalled();
743+
});
734744
});
735745
});

0 commit comments

Comments
 (0)