test: coverage on atomWithSyncStorage (#1779)
This commit is contained in:
1 parent
e02ab36aae
commit
5e56728dbc
1 file changed
+36
@@ -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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user