import { expectType } from './tutorial.test.js'; import Updux from './Updux.js'; const bar = new Updux({ initialState: 123 }); const foo = new Updux({ initialState: { root: 'abc' }, subduxes: { bar, }, }); test('default', () => { const { initialState } = new Updux({}); expect(initialState).toBeTypeOf('object'); expect(initialState).toEqual({}); }); test('number', () => { const { initialState } = new Updux({ initialState: 3 }); expect(initialState).toBeTypeOf('number'); expect(initialState).toEqual(3); }); test('initialState to createStore', () => { const initialState = { a: 1, b: 2, }; const dux = new Updux({ initialState, }); expect(dux.createStore({ preloadedState: { a: 3, b: 4 } }).getState()).toEqual({ a: 3, b: 4, }); }); test('single dux', () => { const foo = new Updux({ initialState: { a: 1 }, }); expect(foo.initialState).toEqual({ a: 1 }); }); // TODO add 'check for no todo eslint rule' test('initialState value', () => { expect(foo.initialState).toEqual({ root: 'abc', bar: 123, }); expectType(foo.initialState); }); test('no initialState', () => { const dux = new Updux({}); expectType(dux.initialState); expect(dux.initialState).toEqual({}); }); test('no initialState for subdux', () => { const dux = new Updux({ subduxes: { bar: new Updux({}), baz: new Updux({ initialState: 'potato' }), }, }); expectType(dux.initialState); expect(dux.initialState).toEqual({ bar: {}, baz: 'potato' }); }); test.todo('splat initialState', () => { const bar = new Updux({ initialState: { id: 0 }, }); const foo = new Updux({ subduxes: { '*': bar }, }); expect(foo.initialState).toEqual([]); expect(new Updux({ initialState: 'overriden', subduxes: { '*': bar }, }).initialState).toEqual('overriden'); });