You've already forked element-web
mirror of
https://github.com/element-hq/element-web.git
synced 2025-08-09 14:42:51 +03:00
test: use forceCloseAllModals
instead of closeCurrentModal
(#30211)
This commit is contained in:
@@ -188,35 +188,11 @@ export const waitEnoughCyclesForModal = async ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A horrible hack necessary to make sure modals don't leak and pollute tests.
|
* Clears all modals that are currently open.
|
||||||
* `jest-matrix-react` automatic cleanup function does not pick up the async modal
|
|
||||||
* rendering and the modals don't unmount when the component unmounts. We should strive
|
|
||||||
* to fix this.
|
|
||||||
*/
|
*/
|
||||||
export const clearAllModals = async (): Promise<void> => {
|
export const clearAllModals = async (): Promise<void> => {
|
||||||
// Prevent modals from leaking and polluting other tests
|
// Prevent modals from leaking and polluting other tests
|
||||||
let keepClosingModals = true;
|
act(() => Modal.forceCloseAllModals());
|
||||||
while (keepClosingModals) {
|
|
||||||
keepClosingModals = await act(() => Modal.closeCurrentModal());
|
|
||||||
|
|
||||||
// Then wait for the screen to update (probably React rerender and async/await).
|
|
||||||
// Important for tests using Jest fake timers to not get into an infinite loop
|
|
||||||
// of removing the same modal because the promises don't flush otherwise.
|
|
||||||
//
|
|
||||||
// XXX: Maybe in the future with Jest 29.5.0+, we could use `runAllTimersAsync` instead.
|
|
||||||
|
|
||||||
// this is called in some places where timers are not faked
|
|
||||||
// which causes a lot of noise in the console
|
|
||||||
// to make a hack even hackier check if timers are faked using a weird trick from github
|
|
||||||
// then call the appropriate promise flusher
|
|
||||||
// https://github.com/facebook/jest/issues/10555#issuecomment-1136466942
|
|
||||||
const jestTimersFaked = setTimeout.name === "setTimeout";
|
|
||||||
if (jestTimersFaked) {
|
|
||||||
await flushPromisesWithFakeTimers();
|
|
||||||
} else {
|
|
||||||
await flushPromises();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Install a stub object at `navigator.mediaDevices` */
|
/** Install a stub object at `navigator.mediaDevices` */
|
||||||
|
@@ -45,9 +45,9 @@ describe("AddRemoveThreepids", () => {
|
|||||||
client = stubClient();
|
client = stubClient();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(async () => {
|
||||||
jest.restoreAllMocks();
|
jest.restoreAllMocks();
|
||||||
clearAllModals();
|
await clearAllModals();
|
||||||
cleanup();
|
cleanup();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -61,14 +61,14 @@ exports[`AddRemoveThreepids should render email addresses 1`] = `
|
|||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
autocomplete="email"
|
autocomplete="email"
|
||||||
id="mx_Field_14"
|
id="mx_Field_15"
|
||||||
label="Email Address"
|
label="Email Address"
|
||||||
placeholder="Email Address"
|
placeholder="Email Address"
|
||||||
type="text"
|
type="text"
|
||||||
value=""
|
value=""
|
||||||
/>
|
/>
|
||||||
<label
|
<label
|
||||||
for="mx_Field_14"
|
for="mx_Field_15"
|
||||||
>
|
>
|
||||||
Email Address
|
Email Address
|
||||||
</label>
|
</label>
|
||||||
@@ -148,14 +148,14 @@ exports[`AddRemoveThreepids should render phone numbers 1`] = `
|
|||||||
</span>
|
</span>
|
||||||
<input
|
<input
|
||||||
autocomplete="tel-national"
|
autocomplete="tel-national"
|
||||||
id="mx_Field_15"
|
id="mx_Field_16"
|
||||||
label="Phone Number"
|
label="Phone Number"
|
||||||
placeholder="Phone Number"
|
placeholder="Phone Number"
|
||||||
type="text"
|
type="text"
|
||||||
value=""
|
value=""
|
||||||
/>
|
/>
|
||||||
<label
|
<label
|
||||||
for="mx_Field_15"
|
for="mx_Field_16"
|
||||||
>
|
>
|
||||||
Phone Number
|
Phone Number
|
||||||
</label>
|
</label>
|
||||||
|
Reference in New Issue
Block a user