Skip to content

test(react/vanilla-utils/atomWithStorage): add test for 'getOnInit' option reading stored value on init#3252

Merged
dai-shi merged 2 commits intopmndrs:mainfrom
sukvvon:test/atomWithStorage-getOnInit
Mar 4, 2026
Merged

test(react/vanilla-utils/atomWithStorage): add test for 'getOnInit' option reading stored value on init#3252
dai-shi merged 2 commits intopmndrs:mainfrom
sukvvon:test/atomWithStorage-getOnInit

Conversation

@sukvvon
Copy link
Contributor

@sukvvon sukvvon commented Mar 4, 2026

Related Bug Reports or Discussions

N/A

Summary

  • Add test for atomWithStorage with getOnInit: true option
    • Verifies that stored value (10) is used as initial value instead of initialValue (0) on first render

Check List

  • pnpm run fix for formatting and linting code and docs

@vercel
Copy link

vercel bot commented Mar 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
jotai Ready Ready Preview, Comment Mar 4, 2026 4:40am

Request Review

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 4, 2026

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 4, 2026

More templates

npm i https://pkg.pr.new/jotai@3252

commit: 87c7267

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

LiveCodes Preview in LiveCodes

Latest commit: 707894c
Last updated: Mar 4, 2026 4:40am (UTC)

Playground Link
React demo https://livecodes.io?x=id/6UZDGZFJQ

See documentations for usage instructions.

Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

Not a valid test.


it('should get stored value on init with getOnInit option', () => {
const countAtom = atomWithStorage('count', 0, dummyStorage, {
getOnInit: true,
Copy link
Member

Choose a reason for hiding this comment

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

This test passes even if we make getOnInit: false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dai-shi 707894c Changed to use store.get to verify the value before mount. The test now fails with getOnInit: false (expected +0 to be 10), confirming it correctly validates the getOnInit behavior.

@dai-shi dai-shi merged commit b1f01c3 into pmndrs:main Mar 4, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants