File tree 1 file changed +10
-4
lines changed
site/src/modules/resources
1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change 1
- import { renderHook } from "@testing-library/react" ;
1
+ import { renderHook , waitFor } from "@testing-library/react" ;
2
2
import type { WorkspaceAgentLog } from "api/typesGenerated" ;
3
3
import WS from "jest-websocket-mock" ;
4
4
import { MockWorkspaceAgent } from "testHelpers/entities" ;
@@ -29,17 +29,23 @@ describe("useAgentLogs", () => {
29
29
30
30
// Send 3 logs
31
31
server . send ( JSON . stringify ( generateLogs ( 3 ) ) ) ;
32
- expect ( result . current ) . toHaveLength ( 3 ) ;
32
+ await waitFor ( ( ) => {
33
+ expect ( result . current ) . toHaveLength ( 3 ) ;
34
+ } ) ;
33
35
34
36
// Disable the hook
35
37
rerender ( { enabled : false } ) ;
36
- expect ( result . current ) . toHaveLength ( 0 ) ;
38
+ await waitFor ( ( ) => {
39
+ expect ( result . current ) . toHaveLength ( 0 ) ;
40
+ } ) ;
37
41
38
42
// Enable the hook again
39
43
rerender ( { enabled : true } ) ;
40
44
await server . connected ;
41
45
server . send ( JSON . stringify ( generateLogs ( 3 ) ) ) ;
42
- expect ( result . current ) . toHaveLength ( 3 ) ;
46
+ await waitFor ( ( ) => {
47
+ expect ( result . current ) . toHaveLength ( 3 ) ;
48
+ } ) ;
43
49
} ) ;
44
50
} ) ;
45
51
You can’t perform that action at this time.
0 commit comments