setInt(num => (num < 200 ? num + 50 : 0))}>
+
setInt(num => (num < 300 ? num + 50 : 0))}>
count: {data}
)
@@ -97,31 +95,31 @@ describe('useSWR - refresh', () => {
// mount
await screen.findByText('count: 0')
- await act(() => advanceTimers(100))
+ await act(() => advanceTimers(200)) // update
screen.getByText('count: 1')
await act(() => advanceTimers(50))
screen.getByText('count: 1')
- await act(() => advanceTimers(50))
+ await act(() => advanceTimers(200))
screen.getByText('count: 2')
- fireEvent.click(screen.getByText('count: 2'))
+ fireEvent.click(screen.getByText('count: 2')) // interval change to 250ms
- await act(() => advanceTimers(100))
+ await act(() => advanceTimers(50))
screen.getByText('count: 2')
- await act(() => advanceTimers(50))
+ await act(() => advanceTimers(200))
screen.getByText('count: 3')
- await act(() => advanceTimers(150))
+ await act(() => advanceTimers(250))
screen.getByText('count: 4')
fireEvent.click(screen.getByText('count: 4'))
await act(() => {
- // it will clear the 150ms timer and set up a new 200ms timer
+ // it will clear the 250ms timer and set up a new 300ms timer
return advanceTimers(150)
})
screen.getByText('count: 4')
- await act(() => advanceTimers(50))
+ await act(() => advanceTimers(150))
screen.getByText('count: 5')
fireEvent.click(screen.getByText('count: 5'))
await act(() => {
@@ -129,7 +127,7 @@ describe('useSWR - refresh', () => {
return advanceTimers(50)
})
screen.getByText('count: 5')
- await act(() => advanceTimers(50))
+ await act(() => advanceTimers(300))
screen.getByText('count: 5')
})
@@ -141,7 +139,7 @@ describe('useSWR - refresh', () => {
const [flag, setFlag] = useState(0)
const shouldPoll = flag < STOP_POLLING_THRESHOLD
const { data } = useSWR(key, () => count++, {
- refreshInterval: shouldPoll ? 100 : 0,
+ refreshInterval: shouldPoll ? 200 : 0,
dedupingInterval: 50,
onSuccess() {
setFlag(value => value + 1)
@@ -159,41 +157,41 @@ describe('useSWR - refresh', () => {
await screen.findByText('count: 0 1')
- await act(() => advanceTimers(100))
+ await act(() => advanceTimers(200))
screen.getByText('count: 1 2')
- await act(() => advanceTimers(100))
+ await act(() => advanceTimers(200))
screen.getByText('count: 1 2')
- await act(() => advanceTimers(100))
+ await act(() => advanceTimers(200))
screen.getByText('count: 1 2')
- await act(() => advanceTimers(100))
+ await act(() => advanceTimers(200))
screen.getByText('count: 1 2')
fireEvent.click(screen.getByText('count: 1 2'))
await act(() => {
- // it will set up a new 100ms timer
+ // it will set up a new 200ms timer
return advanceTimers(50)
})
screen.getByText('count: 1 0')
- await act(() => advanceTimers(50))
+ await act(() => advanceTimers(150))
screen.getByText('count: 2 1')
- await act(() => advanceTimers(100))
+ await act(() => advanceTimers(200))
screen.getByText('count: 3 2')
- await act(() => advanceTimers(100))
+ await act(() => advanceTimers(200))
screen.getByText('count: 3 2')
- await act(() => advanceTimers(100))
+ await act(() => advanceTimers(200))
screen.getByText('count: 3 2')
})
@@ -245,16 +243,16 @@ describe('useSWR - refresh', () => {
screen.getByText('loading')
await screen.findByText('1')
- expect(fetcher).toBeCalledTimes(1)
- expect(fetcher).toReturnWith({
+ expect(fetcher).toHaveBeenCalledTimes(1)
+ expect(fetcher).toHaveReturnedWith({
timestamp: 1,
version: '1.0'
})
fireEvent.click(screen.getByText('1'))
await act(() => advanceTimers(1))
- expect(fetcher).toBeCalledTimes(2)
- expect(fetcher).toReturnWith({
+ expect(fetcher).toHaveBeenCalledTimes(2)
+ expect(fetcher).toHaveReturnedWith({
timestamp: 2,
version: '1.0'
})
@@ -524,17 +522,17 @@ describe('useSWR - refresh', () => {
// initial revalidate
await act(() => advanceTimers(200))
- expect(fetcherWithToken).toBeCalledTimes(1)
+ expect(fetcherWithToken).toHaveBeenCalledTimes(1)
// first refresh
await act(() => advanceTimers(100))
- expect(fetcherWithToken).toBeCalledTimes(2)
+ expect(fetcherWithToken).toHaveBeenCalledTimes(2)
expect(fetcherWithToken).toHaveBeenLastCalledWith(`${key}-0`)
await act(() => advanceTimers(200))
// second refresh start
await act(() => advanceTimers(100))
- expect(fetcherWithToken).toBeCalledTimes(3)
+ expect(fetcherWithToken).toHaveBeenCalledTimes(3)
expect(fetcherWithToken).toHaveBeenLastCalledWith(`${key}-0`)
// change the key during revalidation
// The second refresh will not start a new timer
@@ -542,13 +540,13 @@ describe('useSWR - refresh', () => {
// first, refresh with new key 1
await act(() => advanceTimers(100))
- expect(fetcherWithToken).toBeCalledTimes(4)
+ expect(fetcherWithToken).toHaveBeenCalledTimes(4)
expect(fetcherWithToken).toHaveBeenLastCalledWith(`${key}-1`)
await act(() => advanceTimers(200))
// second refresh with new key 1
await act(() => advanceTimers(100))
- expect(fetcherWithToken).toBeCalledTimes(5)
+ expect(fetcherWithToken).toHaveBeenCalledTimes(5)
expect(fetcherWithToken).toHaveBeenLastCalledWith(`${key}-1`)
})
@@ -579,20 +577,20 @@ describe('useSWR - refresh', () => {
// initial revalidate
await act(() => advanceTimers(100))
- expect(fetcherWithToken).toBeCalledTimes(1)
- expect(onSuccess).toBeCalledTimes(1)
+ expect(fetcherWithToken).toHaveBeenCalledTimes(1)
+ expect(onSuccess).toHaveBeenCalledTimes(1)
expect(onSuccess).toHaveLastReturnedWith(`0-${key} 0-${key}`)
// first refresh
await act(() => advanceTimers(50))
- expect(fetcherWithToken).toBeCalledTimes(2)
+ expect(fetcherWithToken).toHaveBeenCalledTimes(2)
expect(fetcherWithToken).toHaveBeenLastCalledWith(`0-${key}`)
await act(() => advanceTimers(100))
- expect(onSuccess).toBeCalledTimes(2)
+ expect(onSuccess).toHaveBeenCalledTimes(2)
expect(onSuccess).toHaveLastReturnedWith(`0-${key} 0-${key}`)
// second refresh start
await act(() => advanceTimers(50))
- expect(fetcherWithToken).toBeCalledTimes(3)
+ expect(fetcherWithToken).toHaveBeenCalledTimes(3)
expect(fetcherWithToken).toHaveBeenLastCalledWith(`0-${key}`)
// change the key during revalidation
// The second refresh will not start a new timer
@@ -600,15 +598,15 @@ describe('useSWR - refresh', () => {
// first, refresh with new key 1
await act(() => advanceTimers(50))
- expect(fetcherWithToken).toBeCalledTimes(4)
+ expect(fetcherWithToken).toHaveBeenCalledTimes(4)
expect(fetcherWithToken).toHaveBeenLastCalledWith(`1-${key}`)
await act(() => advanceTimers(100))
- expect(onSuccess).toBeCalledTimes(3)
+ expect(onSuccess).toHaveBeenCalledTimes(3)
expect(onSuccess).toHaveLastReturnedWith(`1-${key} 1-${key}`)
// second refresh with new key 1
await act(() => advanceTimers(50))
- expect(fetcherWithToken).toBeCalledTimes(5)
+ expect(fetcherWithToken).toHaveBeenCalledTimes(5)
expect(fetcherWithToken).toHaveBeenLastCalledWith(`1-${key}`)
})
diff --git a/test/use-swr-remote-mutation.test.tsx b/test/use-swr-remote-mutation.test.tsx
index 955d2b9b24..79c94c8e73 100644
--- a/test/use-swr-remote-mutation.test.tsx
+++ b/test/use-swr-remote-mutation.test.tsx
@@ -850,7 +850,7 @@ describe('useSWR - remote mutation', () => {
fireEvent.click(screen.getByText('trigger'))
await nextTick()
- expect(catchError).toBeCalled()
+ expect(catchError).toHaveBeenCalled()
})
it('should support optimistic updates', async () => {
@@ -1120,13 +1120,15 @@ describe('useSWR - remote mutation', () => {
const onRejected = jest.fn()
const fetcher = () => {
- return new Promise((_, reject) => reject(''));
- };
+ return new Promise((_, reject) => reject(''))
+ }
function Page() {
const { trigger } = useSWRMutation(key, fetcher, { onError, onSuccess })
- return
+ return (
+
+ )
}
render(
)
diff --git a/test/use-swr-server.test.tsx b/test/use-swr-server.test.tsx
index 2f7dffa123..b27b7335dc 100644
--- a/test/use-swr-server.test.tsx
+++ b/test/use-swr-server.test.tsx
@@ -30,7 +30,6 @@ describe('useSWR - SSR', () => {
})
it('should enable the IS_SERVER flag - suspense on server without fallback', async () => {
await withServer(async () => {
- // eslint-disable-next-line @typescript-eslint/no-empty-function
jest.spyOn(console, 'error').mockImplementation(() => {})
const useSWR = (await import('swr')).default
diff --git a/test/use-swr-subscription.test.tsx b/test/use-swr-subscription.test.tsx
index d8dfb1ed30..9ec9c100d5 100644
--- a/test/use-swr-subscription.test.tsx
+++ b/test/use-swr-subscription.test.tsx
@@ -294,7 +294,6 @@ describe('useSWRSubscription', () => {
})
it('should require a dispose function', async () => {
- // eslint-disable-next-line @typescript-eslint/no-empty-function
jest.spyOn(console, 'error').mockImplementation(() => {})
const swrKey = createKey()
diff --git a/test/use-swr-suspense.test.tsx b/test/use-swr-suspense.test.tsx
index 1b0e07b227..dcf95159ec 100644
--- a/test/use-swr-suspense.test.tsx
+++ b/test/use-swr-suspense.test.tsx
@@ -5,6 +5,7 @@ import useSWR, { mutate } from 'swr'
import {
createKey,
createResponse,
+ itShouldSkipForReactCanary,
renderWithConfig,
renderWithGlobalCache,
sleep
@@ -17,7 +18,7 @@ describe('useSWR - suspense', () => {
jest.restoreAllMocks()
})
- it('should render fallback', async () => {
+ itShouldSkipForReactCanary('should render suspense fallback', async () => {
const key = createKey()
function Section() {
const { data } = useSWR(key, () => createResponse('SWR'), {
@@ -37,41 +38,44 @@ describe('useSWR - suspense', () => {
await screen.findByText('SWR')
})
- it('should render multiple SWR fallbacks', async () => {
- const key = createKey()
- function Section() {
- const { data: v1 } = useSWR
(
- key,
- () => createResponse(1, { delay: 50 }),
- {
- suspense: true
- }
- )
- const { data: v2 } = useSWR(
- 'suspense-3',
- () => createResponse(2, { delay: 50 }),
- {
- suspense: true
- }
- )
- return {v1 + v2}
- }
+ itShouldSkipForReactCanary(
+ 'should render multiple SWR fallbacks',
+ async () => {
+ const key = createKey()
+ function Section() {
+ const { data: v1 } = useSWR(
+ key,
+ () => createResponse(1, { delay: 50 }),
+ {
+ suspense: true
+ }
+ )
+ const { data: v2 } = useSWR(
+ 'suspense-3',
+ () => createResponse(2, { delay: 50 }),
+ {
+ suspense: true
+ }
+ )
+ return {v1 + v2}
+ }
- renderWithConfig(
- fallback }>
-