11import type { Awaitable , StorageLikeAsync } from '@vueuse/core'
22import { createEventHook , useStorageAsync } from '@vueuse/core'
3- import { beforeEach , describe , expect , it } from 'vitest'
3+ import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest'
44
55const KEY = 'custom-key'
66const KEY2 = 'custom-key2'
@@ -38,6 +38,11 @@ class AsyncStubStorage implements StorageLikeAsync {
3838describe ( 'useStorageAsync' , ( ) => {
3939 beforeEach ( ( ) => {
4040 localStorage . clear ( )
41+ vi . useFakeTimers ( )
42+ } )
43+
44+ afterEach ( ( ) => {
45+ vi . useRealTimers ( )
4146 } )
4247
4348 it ( 'onReady' , async ( ) => {
@@ -60,7 +65,9 @@ describe('useStorageAsync', () => {
6065 )
6166
6267 expect ( storage . value ) . toBe ( '' )
63- await expect ( promise ) . resolves . toBe ( 'CurrentValue' )
68+ vi . waitFor ( async ( ) => {
69+ await expect ( promise ) . resolves . toBe ( 'CurrentValue' )
70+ } )
6471 } )
6572
6673 it ( 'onReadyByPromise' , async ( ) => {
@@ -74,7 +81,8 @@ describe('useStorageAsync', () => {
7481
7582 expect ( storage . value ) . toBe ( '' )
7683
77- storage . then ( ( result ) => {
84+ vi . waitFor ( async ( ) => {
85+ const result = await storage
7886 expect ( result . value ) . toBe ( 'AnotherValue' )
7987 } )
8088 } )
0 commit comments