Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

test(sheets-formula): replace setTimeout with `SetFormulaCalculationResultMutation` wait (#6917)

白熱9a07a9bc2997
diff --git a/packages/sheets-formula/src/controllers/__tests__/array-formula-spill.worker.spec.ts b/packages/sheets-formula/src/controllers/__tests__/array-formula-spill.worker.spec.ts
index 5c3c91932c..e531daa448 100644
--- a/packages/sheets-formula/src/controllers/__tests__/array-formula-spill.worker.spec.ts
+++ b/packages/sheets-formula/src/controllers/__tests__/array-formula-spill.worker.spec.ts
@@ -262,10 +262,21 @@ describe('Array formula SPILL with worker formula calculation', () => {
testBed.workerInjector.get(CalculateController);
const calculationEnd = testBed.workerFormulaEngine.onCalculationEnd();
+
+ // Also wait for the calculation result to be synced back to the main thread.
+ const resultSyncedToMain = new Promise<void>((resolve) => {
+ const disposable = commandService.onCommandExecuted((commandInfo) => {
+ if (commandInfo.id === SetFormulaCalculationResultMutation.id) {
+ disposable.dispose();
+ resolve();
+ }
+ });
+ });
+
testBed.workerCommandService.syncExecuteCommand(SetFormulaCalculationStartMutation.id, { forceCalculation: true }, { onlyLocal: true });
await calculationEnd;
- await new Promise<void>((resolve) => setTimeout(resolve, 0));
- await waitForMicrotasks(12);
+ await resultSyncedToMain;
+ await waitForMicrotasks(2);
}
async function setCell(row: number, column: number, value: number) {