Skip to content

Commit

Permalink
apply review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
vangie committed Sep 27, 2024
1 parent 22f08e7 commit d26dc23
Showing 1 changed file with 0 additions and 21 deletions.
21 changes: 0 additions & 21 deletions tests/vanilla/utils/atomWithReset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,24 @@ describe('atomWithReset', () => {
testAtom = atomWithReset(initialValue)
})

it('should create an atom with initial value', () => {
const { init } = testAtom
expect(init).toBe(initialValue)
})

it('should reset to initial value using RESET', () => {
const store = createStore()
store.set(testAtom, 123)
store.set(testAtom, RESET)
expect(store.get(testAtom)).toBe(initialValue)

const set = vi.fn()
const get = vi.fn(() => 20)
testAtom.write(get, set, RESET)
expect(set).toHaveBeenCalledWith(testAtom, initialValue)
})

it('should update atom with a new value', () => {
const store = createStore()
store.set(testAtom, 123)
store.set(testAtom, 30)
expect(store.get(testAtom)).toBe(30)

const set = vi.fn()
const get = vi.fn(() => 20)
testAtom.write(get, set, 30)
expect(set).toHaveBeenCalledWith(testAtom, 30)
})

it('should update atom using a function', () => {
const store = createStore()
store.set(testAtom, 123)
store.set(testAtom, (prev: number) => prev + 10)
expect(store.get(testAtom)).toBe(133)

const set = vi.fn()
const get = vi.fn(() => 20)
const updateFn = (prev: number) => prev + 10
testAtom.write(get, set, updateFn)
expect(set).toHaveBeenCalledWith(testAtom, 30)
})
})

0 comments on commit d26dc23

Please sign in to comment.