Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

test: coverage on `atomWithSyncStorage` (#1779)

Himself655e56728dbc06
diff --git a/packages/jotai/src/__tests__/index.spec.ts b/packages/jotai/src/__tests__/index.spec.ts
new file mode 100644
index 0000000000..7d69e2d73d
--- /dev/null
+++ b/packages/jotai/src/__tests__/index.spec.ts
@@ -0,0 +1,36 @@
+/**
+ * @vitest-environment happy-dom
+ */
+import { atomWithSyncStorage } from '@affine/jotai';
+import { createStore } from 'jotai';
+import { afterEach, describe, expect, test } from 'vitest';
+
+afterEach(() => {
+ localStorage.clear();
+});
+
+describe('atomWithSyncStorage', () => {
+ test('basic', () => {
+ const store = createStore();
+ {
+ [0, '0', false, null, undefined, NaN].forEach(value => {
+ const atom = atomWithSyncStorage('test', value);
+ expect(store.get(atom)).toBe(value);
+ });
+ }
+ });
+ test('mutate', () => {
+ {
+ const store = createStore();
+ const atom = atomWithSyncStorage('test', 0);
+ expect(store.get(atom)).toBe(0);
+ store.set(atom, 1);
+ expect(store.get(atom)).toBe(1);
+ }
+ {
+ const store = createStore();
+ const atom = atomWithSyncStorage('test', 0);
+ expect(store.get(atom)).toBe(1);
+ }
+ });
+});