sadpandajoe commented on code in PR #45751:
URL: https://github.com/apache/superset/pull/45751#discussion_r4384006133
##########
superset-frontend/src/components/Datasource/DatasourceModal/DatasourceModal.pendingEdits.test.tsx:
##########
@@ -53,13 +53,20 @@ type AceNode = HTMLElement & {
};
};
-/** Flushes the real controls' debounces while leaving their callbacks intact.
*/
-async function settleInputs() {
- await act(async () => {
- await new Promise(resolve =>
- setTimeout(resolve, Math.max(Constants.FAST_DEBOUNCE, 300) + 25),
- );
+// Controls debounce their onChange by FAST_DEBOUNCE (SQL controls use an
+// explicit 300ms, see DatasourceEditor.tsx), via a real setTimeout. Faking
+// timers just long enough to advance past that, mirroring the sibling
+// DatasourceModal.test.tsx / CollectionTable.debounce.test.tsx pattern,
+// settles the same callback deterministically and without the wall-clock
+// wait — real timers resume immediately after so userEvent's own internal
+// timing is unaffected.
+/** Flushes the real controls' debounces without burning real wall-clock time.
*/
+function flushDebounce() {
+ jest.useFakeTimers();
Review Comment:
The debounced edits are scheduled by the real timers before
`jest.useFakeTimers()` runs here, and Jest doesn't move already-scheduled
native timeouts into the fake clock, so `advanceTimersByTime` can't flush them.
After this the placeholder-row assertion and the later save click can run
before the pending onChange fires, which makes the test racy and weaker than
the old 325ms real wait (the sibling `DatasourceModal.test.tsx` enables fake
timers before `fireEvent.change`). Could the fake timers be installed before
the edits (e.g. in `beforeEach`, with `useRealTimers` in `afterEach`), or could
this wait on an assertion with `waitFor` instead? Also the PR description says
40s but the code uses 30000.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]