Skip to content

Commit

Permalink
update react latest
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Dec 19, 2024
1 parent 20d5925 commit 9d57791
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 56 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
"jotai": "^2.8.4",
"jotai-valtio": "link:.",
"prettier": "^3.3.2",
"react": "19.0.0-rc.0",
"react-dom": "19.0.0-rc.0",
"react": "19.0.0",
"react-dom": "19.0.0",
"ts-expect": "^1.3.0",
"typescript": "^5.5.3",
"valtio": "2.1.2",
Expand Down
46 changes: 23 additions & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 36 additions & 31 deletions tests/atomWithProxy.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { afterEach, expect, test } from 'vitest';
import { StrictMode, Suspense } from 'react';
import { cleanup, render } from '@testing-library/react';
import { act, cleanup, render, screen } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';
import { useAtom } from 'jotai/react';
import { atom } from 'jotai/vanilla';
Expand Down Expand Up @@ -33,20 +33,20 @@ test('count state', async () => {
);
};

const { findByText, getByText } = render(
render(
<StrictMode>
<Counter />
</StrictMode>,
);

await findByText('count: 1');
await screen.findByText('count: 1');

await userEvent.click(getByText('button'));
await findByText('count: 2');
await userEvent.click(screen.getByText('button'));
await screen.findByText('count: 2');
expect(proxyState.count).toBe(2);

++proxyState.count;
await findByText('count: 3');
await screen.findByText('count: 3');
expect(proxyState.count).toBe(3);
});

Expand Down Expand Up @@ -74,21 +74,21 @@ test('nested count state', async () => {
);
};

const { findByText, getByText } = render(
render(
<StrictMode>
<Counter />
</StrictMode>,
);

await findByText('count: 0');
await screen.findByText('count: 0');

await userEvent.click(getByText('button'));
await findByText('count: 1');
await userEvent.click(screen.getByText('button'));
await screen.findByText('count: 1');
expect(proxyState.nested.count).toBe(1);
expect(otherSnap === snapshot(proxyState.other)).toBe(true);

++proxyState.nested.count;
await findByText('count: 2');
await screen.findByText('count: 2');
expect(proxyState.nested.count).toBe(2);
expect(otherSnap === snapshot(proxyState.other)).toBe(true);
});
Expand Down Expand Up @@ -122,22 +122,27 @@ test('state with a promise', async () => {
);
};

const { findByText, getByText } = render(
<StrictMode>
<Suspense fallback="loading">
<Status />
</Suspense>
</StrictMode>,
);
const Controls = () => <button onClick={() => resolve()}>resolve</button>;

await act(async () => {
render(
<StrictMode>
<Controls />
<Suspense fallback="loading">
<Status />
</Suspense>
</StrictMode>,
);
});

await findByText('loading');
await screen.findByText('loading');
resolve();
await findByText('status: done');
await screen.findByText('status: done');

await userEvent.click(getByText('button'));
await findByText('loading');
await userEvent.click(screen.getByText('button'));
await screen.findByText('loading');
resolve();
await findByText('status: modified');
await screen.findByText('status: modified');
});

test('synchronous atomWithProxy and regular atom ', async () => {
Expand Down Expand Up @@ -176,15 +181,15 @@ test('synchronous atomWithProxy and regular atom ', async () => {
);
};

const { findByText, getByText } = render(
render(
<StrictMode>
<Elements />
</StrictMode>,
);

await findByText('selected element: none');
await userEvent.click(getByText('create and select element'));
getByText('selected element: element'); // synchronous
await screen.findByText('selected element: none');
await userEvent.click(screen.getByText('create and select element'));
screen.getByText('selected element: element'); // synchronous
});

test('array.length state', async () => {
Expand All @@ -202,15 +207,15 @@ test('array.length state', async () => {
);
};

const { findByText, getByText } = render(
render(
<StrictMode>
<Counter />
</StrictMode>,
);

await findByText('array0: 0');
await userEvent.click(getByText('button'));
await screen.findByText('array0: 0');
await userEvent.click(screen.getByText('button'));

await findByText('array0: 1');
await screen.findByText('array0: 1');
expect(proxyState.array.length).toBe(1);
});

0 comments on commit 9d57791

Please sign in to comment.