Skip to content

Commit

Permalink
test(models/project): flush promises after `vi.runOnlyPendingTimersAs…
Browse files Browse the repository at this point in the history
…ync` (goplus#965)

Tests show that `vi.runOnlyPendingTimersAsync` triggers timers but
doesn't await async resolutions like `vi.advanceTimersToNextTimerAsync`,
despite Vitest's documentation not specifying this.

Signed-off-by: Aofei Sheng <aofei@aofeisheng.com>
  • Loading branch information
aofei authored Sep 30, 2024
1 parent d2b359d commit f06922f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spx-gui/src/models/project/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ describe('Project', () => {
expect(project.hasUnsyncedChanges).toBe(true)

await vi.runOnlyPendingTimersAsync()
await flushPromises()
expect(project.autoSaveToCloudState).toBe(AutoSaveToCloudState.Failed)
expect(project.hasUnsyncedChanges).toBe(true)
expect(cloudSaveMock).toHaveBeenCalledTimes(1)
Expand All @@ -238,6 +239,7 @@ describe('Project', () => {
expect(project.hasUnsyncedChanges).toBe(false)

await vi.runOnlyPendingTimersAsync()
await flushPromises()
expect(project.autoSaveToCloudState).toBe(AutoSaveToCloudState.Saved)
expect(project.hasUnsyncedChanges).toBe(false)
expect(cloudSaveMock).toHaveBeenCalledTimes(1)
Expand Down Expand Up @@ -266,6 +268,7 @@ describe('Project', () => {

project.dispose()
await vi.runOnlyPendingTimersAsync()
await flushPromises()
expect(project.autoSaveToCloudState).toBe(AutoSaveToCloudState.Pending)
expect(project.hasUnsyncedChanges).toBe(true)
expect(cloudSaveMock).toHaveBeenCalledTimes(0)
Expand All @@ -286,6 +289,7 @@ describe('Project', () => {

project.dispose()
await vi.runOnlyPendingTimersAsync()
await flushPromises()
expect(localSaveMock).toHaveBeenCalledTimes(0)
})
})

0 comments on commit f06922f

Please sign in to comment.