Skip to content

Commit

Permalink
chore: fix warnings in atomWithStorage test
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Jun 28, 2021
1 parent 59dbb69 commit 03454c7
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions tests/utils/atomWithStorage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import React, { Suspense } from 'react'
import { fireEvent, render } from '@testing-library/react'
import { fireEvent, render, waitFor } from '@testing-library/react'
import { useAtom } from '../../src/index'
import { atomWithStorage, atomWithHash } from '../../src/utils'
import { getTestProvider } from '../testUtils'

const Provider = getTestProvider()

beforeEach(() => {
jest.useFakeTimers()
})
afterEach(() => {
jest.runOnlyPendingTimers()
jest.useRealTimers()
})

describe('atomWithStorage (sync)', () => {
const storageData: Record<string, number> = {
count: 10,
Expand Down Expand Up @@ -93,8 +101,9 @@ describe('atomWithStorage (async)', () => {

fireEvent.click(getByText('button'))
await findByText('count: 11')
await new Promise((r) => setTimeout(r, 20))
expect(asyncStorageData.count).toBe(11)
waitFor(() => {
expect(asyncStorageData.count).toBe(11)
})
})

it('async new count', async () => {
Expand Down Expand Up @@ -123,8 +132,9 @@ describe('atomWithStorage (async)', () => {

fireEvent.click(getByText('button'))
await findByText('count: 21')
await new Promise((r) => setTimeout(r, 20))
expect(asyncStorageData.count2).toBe(21)
waitFor(() => {
expect(asyncStorageData.count2).toBe(21)
})
})

it('async new count with delayInit', async () => {
Expand Down Expand Up @@ -153,8 +163,9 @@ describe('atomWithStorage (async)', () => {

fireEvent.click(getByText('button'))
await findByText('count: 31')
await new Promise((r) => setTimeout(r, 20))
expect(asyncStorageData.count3).toBe(31)
waitFor(() => {
expect(asyncStorageData.count3).toBe(31)
})
})
})

Expand Down

1 comment on commit 03454c7

@vercel
Copy link

@vercel vercel bot commented on 03454c7 Jun 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.