import { test, expect } from 'vitest'; import { action } from './actions.js'; import { Updux } from './Updux.js'; test('basic action', () => { const foo = action('foo', (thing) => ({ thing })); expect(foo('bar')).toEqual({ type: 'foo', payload: { thing: 'bar', }, }); }); test('Updux config accepts actions', () => { const foo = new Updux({ actions: { one: action('one', (x) => ({ x })), two: action('two', (x) => x), }, }); expect(Object.keys(foo.actions)).toHaveLength(2); expect(foo.actions.one).toBeTypeOf('function'); expect(foo.actions.one('potato')).toEqual({ type: 'one', payload: { x: 'potato', }, }); }); test('subduxes actions', () => { const foo = new Updux({ actions: { foo: null, }, subduxes: { beta: { actions: { bar: null, }, }, }, }); expect(foo.actions).toHaveProperty('foo'); expect(foo.actions).toHaveProperty('bar'); });