|
1 | 1 | import { afterEach, test } from 'vitest';
|
2 | 2 | import { StrictMode, Suspense } from 'react';
|
3 | 3 | import { cleanup, fireEvent, render } from '@testing-library/react';
|
4 |
| -import { expectType } from 'ts-expect'; |
5 | 4 | import { useAtom } from 'jotai/react';
|
6 | 5 | import { atom } from 'jotai/vanilla';
|
7 |
| -import type { SetStateAction, WritableAtom } from 'jotai/vanilla'; |
| 6 | +import type { SetStateAction } from 'jotai/vanilla'; |
8 | 7 | import * as O from 'optics-ts';
|
9 | 8 | import { focusAtom } from 'jotai-optics';
|
10 |
| -import type { NotAnArrayType } from 'node_modules/optics-ts/utils.js'; |
11 | 9 | import { useSetAtom } from 'jotai';
|
12 | 10 |
|
13 | 11 | afterEach(cleanup);
|
@@ -145,50 +143,3 @@ test('focus on async atom works', async () => {
|
145 | 143 | await findByText('baseAtom: [0,1,2,3]');
|
146 | 144 | await findByText('asyncAtom: [0,1,2,3]');
|
147 | 145 | });
|
148 |
| - |
149 |
| -type BillingData = { |
150 |
| - id: string; |
151 |
| -}; |
152 |
| - |
153 |
| -type CustomerData = { |
154 |
| - id: string; |
155 |
| - billing: BillingData[]; |
156 |
| - someOtherData: string; |
157 |
| -}; |
158 |
| - |
159 |
| -test('typescript should accept "undefined" as valid value for lens', async () => { |
160 |
| - const customerListAtom = atom<CustomerData[]>([]); |
161 |
| - |
162 |
| - const foundCustomerAtom = focusAtom(customerListAtom, (optic) => |
163 |
| - optic.find((el) => el.id === 'some-invalid-id'), |
164 |
| - ); |
165 |
| - |
166 |
| - const derivedLens = focusAtom(foundCustomerAtom, (optic) => optic.appendTo()); |
167 |
| - |
168 |
| - expectType< |
169 |
| - WritableAtom<void, [NotAnArrayType<CustomerData | undefined>], void> |
170 |
| - >(derivedLens); |
171 |
| -}); |
172 |
| - |
173 |
| -test('should work with promise based atoms with "undefined" value', async () => { |
174 |
| - const customerBaseAtom = atom<CustomerData | undefined>(undefined); |
175 |
| - |
176 |
| - const asyncCustomerDataAtom = atom( |
177 |
| - async (get) => get(customerBaseAtom), |
178 |
| - async (_, set, nextValue: Promise<CustomerData>) => { |
179 |
| - set(customerBaseAtom, await nextValue); |
180 |
| - }, |
181 |
| - ); |
182 |
| - |
183 |
| - const focusedPromiseAtom = focusAtom(asyncCustomerDataAtom, (optic) => |
184 |
| - optic.appendTo(), |
185 |
| - ); |
186 |
| - |
187 |
| - expectType< |
188 |
| - WritableAtom< |
189 |
| - Promise<void>, |
190 |
| - [NotAnArrayType<CustomerData | undefined>], |
191 |
| - Promise<void> |
192 |
| - > |
193 |
| - >(focusedPromiseAtom); |
194 |
| -}); |
0 commit comments