generated from shgysk8zer0/npm-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate.test.js
More file actions
24 lines (22 loc) · 1.04 KB
/
state.test.js
File metadata and controls
24 lines (22 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import './shims.js';
import { test, describe } from 'node:test';
import assert from 'node:assert';
import { manageState, getState, closeChannel } from './state.js';
// Have to close channel because leaving it open would keep the process running.
closeChannel();
const num = getState('num', 42);
const nums = getState('nums', [1, 2, 3]);
const [foo, setFoo] = manageState('foo', 'bar');
setFoo('bar');
const signal = AbortSignal.timeout(300);
describe('Run tests to verify state managmenet operations', () => {
test('Verify getting state.', { signal }, () => assert.equal(getState('foo'), 'bar'));
test('State values should coerce to be equal.', { signal }, () => assert.equal(foo, 'bar'));
test('State values should be objects/proxies.', { signal }, assert.notStrictEqual(foo, 'bar'));
test('State values should work with many operators', { signal }, assert.equal(num + 1, 43));
test('State value proxy should trigger updates', { signal }, () => {
nums.push(4);
assert.equal(nums.reduce((sum, num) => sum + num), 10);
assert.equal(nums[0], 1);
});
});