|
1 | 1 | import { act, fireEvent, render, screen } from '@testing-library/react'
|
2 | 2 | import React, { useState } from 'react'
|
3 |
| -import useSWR from '../src' |
| 3 | +import useSWR, { cache } from '../src' |
4 | 4 | import { sleep } from './utils'
|
5 | 5 |
|
6 | 6 | describe('useSWR - refresh', () => {
|
@@ -201,15 +201,16 @@ describe('useSWR - refresh', () => {
|
201 | 201 | )
|
202 | 202 | })
|
203 | 203 |
|
204 |
| - it('should allow use custom isEqual method', async () => { |
| 204 | + it('should allow use custom compare method', async () => { |
205 | 205 | let count = 0
|
| 206 | + const key = 'dynamic-11' |
206 | 207 | const fetcher = jest.fn(() => ({
|
207 | 208 | timestamp: ++count,
|
208 | 209 | version: '1.0'
|
209 | 210 | }))
|
210 | 211 | function Page() {
|
211 |
| - const { data, mutate: change } = useSWR('dynamic-11', fetcher, { |
212 |
| - compare: function isEqual(a, b) { |
| 212 | + const { data, mutate: change } = useSWR(key, fetcher, { |
| 213 | + compare: function compare(a, b) { |
213 | 214 | if (a === b) {
|
214 | 215 | return true
|
215 | 216 | }
|
@@ -244,6 +245,9 @@ describe('useSWR - refresh', () => {
|
244 | 245 | timestamp: 2,
|
245 | 246 | version: '1.0'
|
246 | 247 | })
|
| 248 | + |
| 249 | + const cachedData = cache.get(key) |
| 250 | + expect(cachedData.timestamp.toString()).toEqual('1') |
247 | 251 | expect(container.firstChild.textContent).toMatchInlineSnapshot(`"1"`)
|
248 | 252 | })
|
249 | 253 |
|
|
0 commit comments