import { test, expect } from 'vitest'; import Updux from './Updux.js'; test('default schema', () => { const dux = new Updux({}); expect(dux.schema).toMatchObject({ type: 'object', }); }); test('basic schema', () => { const dux = new Updux({ schema: { type: 'number' }, }); expect(dux.schema).toMatchObject({ type: 'number', }); }); test('schema default inherits from initial state', () => { const dux = new Updux({ schema: { type: 'number' }, initialState: 8, }); expect(dux.schema.default).toEqual(8); }); test('validate', () => { const dux = new Updux({ initialState: 12, actions: { doItWrong: null, }, }); dux.addMutation('doItWrong', () => () => 'potato'); const store = dux.createStore({ validate: true }); expect(() => store.dispatch.doItWrong()).toThrow(); });