From 4e97a16275a0e6dfb4428caedab169f5c1ead6aa Mon Sep 17 00:00:00 2001 From: Darren Jennings Date: Fri, 2 Jul 2021 19:12:56 -0400 Subject: [PATCH] fix(isValidating): add nullish check when no key (#205) Fixes #195 --- src/use-swrv.ts | 1 + tests/use-swrv.spec.tsx | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/use-swrv.ts b/src/use-swrv.ts index ae8836d..d8b7efc 100644 --- a/src/use-swrv.ts +++ b/src/use-swrv.ts @@ -388,6 +388,7 @@ function useSWRV (...args): IResponse { watch(keyRef, (val) => { keyRef.value = val stateRef.key = val + stateRef.isValidating = Boolean(val) setRefCache(keyRef.value, stateRef, ttl) if (!IS_SERVER && !isHydrated && keyRef.value) { diff --git a/tests/use-swrv.spec.tsx b/tests/use-swrv.spec.tsx index 7bfa1ed..8264d70 100644 --- a/tests/use-swrv.spec.tsx +++ b/tests/use-swrv.spec.tsx @@ -688,6 +688,19 @@ describe('useSWRV - loading', () => { expect(wrapper.text()).toBe('hello, data, ready') done() }) + + // #195 + it('should return loading state isValidating with nullish key', async done => { + const vm = new Vue(defineComponent({ + template: `
{{ error }}:{{this.isValidating ? 'loading' : 'ready'}}
`, + setup () { + return useSWRV(() => null) + } + })).$mount() + + expect(vm.$el.textContent).toBe(':ready') + done() + }) }) describe('useSWRV - mutate', () => {