|
1 | 1 | import { StrictMode, useEffect, useRef } from 'react'
|
2 | 2 | import { render, screen } from '@testing-library/react'
|
3 | 3 | import userEvent from '@testing-library/user-event'
|
4 |
| -import { it } from 'vitest' |
| 4 | +import { expect, it } from 'vitest' |
5 | 5 | import { useAtomValue, useSetAtom } from 'jotai/react'
|
6 | 6 | import { atom } from 'jotai/vanilla'
|
7 | 7 | import { selectAtom } from 'jotai/vanilla/utils'
|
@@ -130,3 +130,18 @@ it('do not update unless equality function says value has changed', async () =>
|
130 | 130 | await screen.findByText('value: {"a":3}')
|
131 | 131 | await screen.findByText('commits: 4')
|
132 | 132 | })
|
| 133 | + |
| 134 | +it('creates fresh cache path when deps differ (memo3)', () => { |
| 135 | + const baseAtom = atom({ a: 0, b: 1 }) |
| 136 | + |
| 137 | + const derivedAtom1 = selectAtom(baseAtom, (v) => v) |
| 138 | + const derivedAtom2 = selectAtom(baseAtom, (v) => v) |
| 139 | + |
| 140 | + expect(derivedAtom1).not.toBe(derivedAtom2) |
| 141 | + |
| 142 | + const selector = (v: { a: number; b: number }) => v.a |
| 143 | + const derivedAtom3 = selectAtom(baseAtom, selector) |
| 144 | + const derivedAtom4 = selectAtom(baseAtom, selector) |
| 145 | + |
| 146 | + expect(derivedAtom3).toBe(derivedAtom4) |
| 147 | +}) |
0 commit comments