atoms-state v0.8.1
git clone https://git.pyrossh.dev/atoms-state
Simple State management for react
index.test.js
| 551beab | 1 | import { atom } from './index'; |
| 6d09b46 | 2 | |
| 6d09b46 | 3 | describe('atom', () => { |
| 6d09b46 | 4 | it('getValue', () => { |
| 6d09b46 | 5 | const atomOne = atom(10); |
| 6d09b46 | 6 | const atomTwo = atom(20); |
| 95fe2b3 | 7 | const sumAtom = atom((get) => get(atomOne) + get(atomTwo)); |
| 6d09b46 | 8 | expect(atomOne.getValue()).toEqual(10); |
| 6d09b46 | 9 | expect(atomTwo.getValue()).toEqual(20); |
| 6d09b46 | 10 | expect(sumAtom.getValue()).toEqual(30); |
| 6d09b46 | 11 | }); |
| 6d09b46 | 12 | |
| 6d09b46 | 13 | it('update', () => { |
| 6d09b46 | 14 | const atomOne = atom(10); |
| 95fe2b3 | 15 | const sumAtom = atom((get) => get(atomOne) + 5); |
| 95fe2b3 | 16 | atomOne.update((v) => v + 2); |
| 6d09b46 | 17 | expect(atomOne.getValue()).toEqual(12); |
| 6d09b46 | 18 | expect(sumAtom.getValue()).toEqual(17); |
| 22fa1eb | 19 | }); |
| 6d09b46 | 20 | |
| 6d09b46 | 21 | it('subscribe', async () => { |
| 6d09b46 | 22 | const atomOne = atom(10); |
| 95fe2b3 | 23 | const sumAtom = atom((get) => get(atomOne) + 5); |
| 95fe2b3 | 24 | atomOne.subscribe((newValue) => expect(newValue).toEqual(15)); |
| 95fe2b3 | 25 | sumAtom.subscribe((newValue) => expect(newValue).toEqual(20)); |
| 95fe2b3 | 26 | atomOne.update((v) => v + 5); |
| 22fa1eb | 27 | }); |
| fcb6563 | 28 | |
| fcb6563 | 29 | // it('useAtom', async () => { |
| fcb6563 | 30 | // }) |
| 6d09b46 | 31 | }); |
| fcb6563 | 32 | |
| fcb6563 | 33 | describe('asyncAtom', () => {}); |
| fcb6563 | 34 | |
| fcb6563 | 35 | describe('usePromise', () => {}); |