Skip to content

Commit

Permalink
test: more
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Dec 24, 2023
1 parent 23185f6 commit a9a88a8
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/use-query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('useQuery', () => {
expect(wrapper.vm.data).toBe(42)
})

it('new mount does not fetch if staleTime is not elaopsed', async () => {
it('new mount does not fetch if staleTime is not elapsed', async () => {
const pinia = createPinia()
const [w1, f1] = mountSimple({ staleTime: 1000 }, { plugins: [pinia] })

Expand Down Expand Up @@ -187,7 +187,36 @@ describe('useQuery', () => {
expect(w2.vm.data).toBe(42)
})

it.todo('reuses a pending request even if the staleTime has been elapsed')
it('new mount reuses a pending request even if the staleTime has been elapsed', async () => {
const pinia = createPinia()
const [w1, f1] = mountSimple({ staleTime: 0 }, { plugins: [pinia] })
// should not trigger a new fetch because staleTime has not passed
vi.advanceTimersByTime(10)
const [w2, f2] = mountSimple({ staleTime: 0 }, { plugins: [pinia] })

await runTimers()

expect(f1).toHaveBeenCalledTimes(1)
expect(f2).toHaveBeenCalledTimes(0)
expect(w1.vm.data).toBe(42)
expect(w2.vm.data).toBe(42)
})

it('refresh reuses a pending request even if the staleTime has been elapsed', async () => {
const pinia = createPinia()
const { wrapper, fetcher } = mountSimple(
{ staleTime: 0 },
{ plugins: [pinia] }
)
// should not trigger a new fetch because staleTime has not passed
vi.advanceTimersByTime(10)
wrapper.vm.refresh()

await runTimers()

expect(fetcher).toHaveBeenCalledTimes(1)
expect(wrapper.vm.data).toBe(42)
})
})

describe.skip('refresh', () => {
Expand Down

0 comments on commit a9a88a8

Please sign in to comment.