Remove test timers related to code block - #380
Merged
Merged
Conversation
fluiddot
approved these changes
Jul 24, 2024
| expect( screen.getByText( 'Running...' ) ).toBeVisible(); | ||
|
|
||
| // Run code execution measurement timer | ||
| await act( () => jest.runAllTimersAsync() ); |
Contributor
There was a problem hiding this comment.
I think we could keep this line if we use fake timers.
diff --git forkSrcPrefix/src/components/tests/assistant-code-block.test.tsx forkDstPrefix/src/components/tests/assistant-code-block.test.tsx
index 2cee11e4fbdacf4383f20ee731f97aaedaadd346..3da280e60c199a619857b02d20ce2d58f64bbfd3 100644
--- forkSrcPrefix/src/components/tests/assistant-code-block.test.tsx
+++ forkDstPrefix/src/components/tests/assistant-code-block.test.tsx
@@ -1,4 +1,4 @@
-import { render, screen, fireEvent, waitFor } from '@testing-library/react';
+import { act, render, screen, fireEvent, waitFor } from '@testing-library/react';
import { getIpcApi } from '../../lib/get-ipc-api';
import createCodeComponent from '../assistant-code-block';
@@ -89,6 +89,14 @@ describe( 'createCodeComponent', () => {
} );
describe( 'when the "run" button is clicked', () => {
+ beforeEach( () => {
+ jest.useFakeTimers();
+ } );
+
+ afterEach( () => {
+ jest.useRealTimers();
+ } );
+
it( 'should display an activity indicator while running code', async () => {
( getIpcApi as jest.Mock ).mockReturnValue( {
executeWPCLiInline: jest.fn().mockResolvedValue( { stdout: 'Mock success', stderr: '' } ),
@@ -100,9 +108,9 @@ describe( 'createCodeComponent', () => {
expect( screen.getByText( 'Running...' ) ).toBeVisible();
- await waitFor( () => {
- expect( screen.queryByText( 'Running...' ) ).not.toBeInTheDocument();
- } );
+ await act( () => jest.runOnlyPendingTimersAsync() );
+
+ expect( screen.queryByText( 'Running...' ) ).not.toBeInTheDocument();
} );
it( 'should display the output of the successfully executed code', async () => {
@@ -113,10 +121,10 @@ describe( 'createCodeComponent', () => {
fireEvent.click( screen.getByText( 'Run' ) );
- await waitFor( () => {
- expect( screen.getByText( 'Success' ) ).toBeVisible();
- expect( screen.getByText( 'Mock success' ) ).toBeVisible();
- } );
+ await act( () => jest.runOnlyPendingTimersAsync() );
+
+ expect( screen.getByText( 'Success' ) ).toBeVisible();
+ expect( screen.getByText( 'Mock success' ) ).toBeVisible();
} );
it( 'should display the output of the failed code execution', async () => {
@@ -127,10 +135,10 @@ describe( 'createCodeComponent', () => {
fireEvent.click( screen.getByText( 'Run' ) );
- await waitFor( () => {
- expect( screen.getByText( 'Error' ) ).toBeVisible();
- expect( screen.getByText( 'Mock error' ) ).toBeVisible();
- } );
+ await act( () => jest.runOnlyPendingTimersAsync() );
+
+ expect( screen.getByText( 'Error' ) ).toBeVisible();
+ expect( screen.getByText( 'Mock error' ) ).toBeVisible();
} );
} );
Member
Author
There was a problem hiding this comment.
sounds good! I reverted that change in favor of the timers cdb3e17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed Changes
npm run test -- --detectOpenHandles. Do not fixes all the cases though.I've observed that running
npm run testthrows this warning:This warning already existed in a704e04 before merging #308
After debugging with
npm run test -- --detectOpenHandles, I got some warning that I've addressed in this PR.Testing Instructions
npm run test -- --detectOpenHandlesPre-merge Checklist