Skip to content

Commit

Permalink
test: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Dec 23, 2023
1 parent 0e7db95 commit 1826a65
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/data-fetching-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ export const useDataFetchingStore = defineStore('PiniaColada', () => {
},
async refetch(): Promise<TResult> {
console.log('🔄 refetching', key)
if (entry.pending) console.log(' -> skipped!')
// when if there an ongoing request
if (!entry.pending) {
console.log(' -> skipped!')
entry.isFetching.value = true
entry.error.value = null
const nextPrevious = {
Expand Down
7 changes: 4 additions & 3 deletions src/use-query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ describe('useQuery', () => {
expect(fetcher).toHaveBeenCalledTimes(1)

// should not trigger a new fetch because staleTime has not passed
await wrapper.vm.refresh()
vi.advanceTimersByTime(500)
wrapper.vm.refresh()
await runTimers()

expect(fetcher).toHaveBeenCalledTimes(1)
Expand All @@ -140,8 +141,8 @@ describe('useQuery', () => {
expect(wrapper.vm.data).toBe(42)
expect(fetcher).toHaveBeenCalledTimes(1)

vi.advanceTimersByTime(1000)
await wrapper.vm.refresh()
vi.advanceTimersByTime(1001)
wrapper.vm.refresh()
await runTimers()

expect(fetcher).toHaveBeenCalledTimes(2)
Expand Down

0 comments on commit 1826a65

Please sign in to comment.