@@ -11,7 +11,7 @@ Please see LICENSE files in the repository root for full details.
11
11
import "core-js/stable/structured-clone" ;
12
12
import "fake-indexeddb/auto" ;
13
13
import React , { ComponentProps } from "react" ;
14
- import { fireEvent , render , RenderResult , screen , waitFor , within } from "jest-matrix-react" ;
14
+ import { fireEvent , render , RenderResult , screen , waitFor , within , act } from "jest-matrix-react" ;
15
15
import fetchMock from "fetch-mock-jest" ;
16
16
import { Mocked , mocked } from "jest-mock" ;
17
17
import { ClientEvent , MatrixClient , MatrixEvent , Room , SyncState } from "matrix-js-sdk/src/matrix" ;
@@ -163,7 +163,7 @@ describe("<MatrixChat />", () => {
163
163
let initPromise : Promise < void > | undefined ;
164
164
let defaultProps : ComponentProps < typeof MatrixChat > ;
165
165
const getComponent = ( props : Partial < ComponentProps < typeof MatrixChat > > = { } ) =>
166
- render ( < MatrixChat { ...defaultProps } { ...props } /> ) ;
166
+ render ( < MatrixChat { ...defaultProps } { ...props } /> , { legacyRoot : true } ) ;
167
167
168
168
// make test results readable
169
169
filterConsole (
@@ -201,7 +201,7 @@ describe("<MatrixChat />", () => {
201
201
// we are logged in, but are still waiting for the /sync to complete
202
202
await screen . findByText ( "Syncing…" ) ;
203
203
// initial sync
204
- client . emit ( ClientEvent . Sync , SyncState . Prepared , null ) ;
204
+ await act ( ( ) => client . emit ( ClientEvent . Sync , SyncState . Prepared , null ) ) ;
205
205
}
206
206
207
207
// let things settle
@@ -263,7 +263,7 @@ describe("<MatrixChat />", () => {
263
263
264
264
// emit a loggedOut event so that all of the Store singletons forget about their references to the mock client
265
265
// (must be sync otherwise the next test will start before it happens)
266
- defaultDispatcher . dispatch ( { action : Action . OnLoggedOut } , true ) ;
266
+ act ( ( ) => defaultDispatcher . dispatch ( { action : Action . OnLoggedOut } , true ) ) ;
267
267
268
268
localStorage . clear ( ) ;
269
269
} ) ;
@@ -328,7 +328,7 @@ describe("<MatrixChat />", () => {
328
328
329
329
expect ( within ( dialog ) . getByText ( errorMessage ) ) . toBeInTheDocument ( ) ;
330
330
// just check we're back on welcome page
331
- await expect ( await screen . findByTestId ( "mx_welcome_screen" ) ) . toBeInTheDocument ( ) ;
331
+ await expect ( screen . findByTestId ( "mx_welcome_screen" ) ) . resolves . toBeInTheDocument ( ) ;
332
332
} ;
333
333
334
334
beforeEach ( ( ) => {
@@ -956,9 +956,11 @@ describe("<MatrixChat />", () => {
956
956
await screen . findByText ( "Powered by Matrix" ) ;
957
957
958
958
// go to login page
959
- defaultDispatcher . dispatch ( {
960
- action : "start_login" ,
961
- } ) ;
959
+ act ( ( ) =>
960
+ defaultDispatcher . dispatch ( {
961
+ action : "start_login" ,
962
+ } ) ,
963
+ ) ;
962
964
963
965
await flushPromises ( ) ;
964
966
@@ -1126,9 +1128,11 @@ describe("<MatrixChat />", () => {
1126
1128
1127
1129
await getComponentAndLogin ( ) ;
1128
1130
1129
- bootstrapDeferred . resolve ( ) ;
1131
+ act ( ( ) => bootstrapDeferred . resolve ( ) ) ;
1130
1132
1131
- await expect ( await screen . findByRole ( "heading" , { name : "You're in" , level : 1 } ) ) . toBeInTheDocument ( ) ;
1133
+ await expect (
1134
+ screen . findByRole ( "heading" , { name : "You're in" , level : 1 } ) ,
1135
+ ) . resolves . toBeInTheDocument ( ) ;
1132
1136
} ) ;
1133
1137
} ) ;
1134
1138
} ) ;
@@ -1397,7 +1401,9 @@ describe("<MatrixChat />", () => {
1397
1401
1398
1402
function simulateSessionLockClaim ( ) {
1399
1403
localStorage . setItem ( "react_sdk_session_lock_claimant" , "testtest" ) ;
1400
- window . dispatchEvent ( new StorageEvent ( "storage" , { key : "react_sdk_session_lock_claimant" } ) ) ;
1404
+ act ( ( ) =>
1405
+ window . dispatchEvent ( new StorageEvent ( "storage" , { key : "react_sdk_session_lock_claimant" } ) ) ,
1406
+ ) ;
1401
1407
}
1402
1408
1403
1409
it ( "after a session is restored" , async ( ) => {
0 commit comments