updux/src/initial.test.js

47 lines
831 B
JavaScript
Raw Normal View History

2022-08-25 01:37:31 +00:00
import { test, expect } from 'vitest';
2021-10-09 00:22:04 +00:00
2022-08-25 01:37:31 +00:00
import { Updux } from './Updux.js';
2021-10-09 00:22:04 +00:00
2022-08-25 14:51:07 +00:00
const bar = new Updux({ initial: 123 });
2022-08-25 14:22:32 +00:00
2022-08-25 01:37:31 +00:00
const foo = new Updux({
initial: { root: 'abc' },
subduxes: {
2022-08-25 14:22:32 +00:00
bar,
2022-08-25 01:37:31 +00:00
},
2021-10-09 00:22:04 +00:00
});
2022-08-25 01:37:31 +00:00
2022-08-25 14:51:07 +00:00
test('single dux', () => {
2022-08-25 14:22:32 +00:00
const foo = new Updux({
2022-08-25 14:51:07 +00:00
initial: { a: 1 },
2022-08-25 14:22:32 +00:00
});
2022-08-25 14:51:07 +00:00
expect(foo.initial).toEqual({ a: 1 });
});
2022-08-25 14:22:32 +00:00
2022-08-25 14:51:07 +00:00
test('initial value', () => {
2022-08-25 01:37:31 +00:00
expect(foo.initial).toEqual({
root: 'abc',
2022-08-25 14:51:07 +00:00
bar: 123,
});
});
2022-08-30 14:55:16 +00:00
2022-08-30 18:16:29 +00:00
test('splat initial', async () => {
2022-08-30 14:55:16 +00:00
const bar = new Updux({
initial: { id: 0 },
});
const foo = new Updux({
subduxes: { '*': bar },
});
expect(foo.initial).toEqual([]);
2022-08-30 18:16:29 +00:00
expect(
new Updux({
initial: 'overriden',
subduxes: { '*': bar },
}).initial,
).toEqual('overriden');
2022-08-30 14:55:16 +00:00
});