test with ts

typescript
Yanick Champoux 2021-10-15 10:41:31 -04:00
parent 83f28a1720
commit 3394a00419
1 changed files with 23 additions and 17 deletions

View File

@ -1,9 +1,7 @@
import { test } from 'tap';
import { Updux } from './Updux';
import { action } from './actions';
import { Updux } from './Updux.js';
import { action } from './actions.js';
test('basic', async (t) => {
test('basic', () => {
const doIt = action('doIt');
const thisToo = action('thisToo');
@ -16,12 +14,12 @@ test('basic', async (t) => {
},
});
t.equal(dux.reducer(undefined, dux.actions.doIt()), 'bingo');
expect(dux.reducer(undefined, dux.actions.doIt())).toEqual( 'bingo');
t.equal(dux.reducer(undefined, dux.actions.thisToo()), 'straight type');
expect(dux.reducer(undefined, dux.actions.thisToo())).toEqual( 'straight type');
});
test('override', async (t) => {
test('override', () => {
const foo = action('foo');
const dux = new Updux({
@ -50,13 +48,14 @@ test('override', async (t) => {
undefined
);
t.match(state, {
expect(state).toMatchObject(
{
alpha: ['foo', 'bar'],
subbie: 1,
});
});
test('order of processing', async (t) => {
test('order of processing', () => {
const foo = action('foo');
const dux = new Updux({
@ -78,26 +77,33 @@ test('order of processing', async (t) => {
},
});
t.same(dux.reducer(undefined, foo()), { x: ['subdux', 'main'] });
expect(dux.reducer(undefined, foo()))
.toMatchObject({ x: ['subdux', 'main'] });
});
test('setMutation', async (t) => {
test('setMutation', () => {
const foo = action('foo');
const dux = new Updux({
initial: '',
});
t.equal(dux.reducer(undefined, foo()), '', 'noop');
// noop
expect(dux.reducer(undefined, foo())).toEqual( '');
dux.setMutation('foo', () => () => 'foo');
t.equal(dux.reducer(undefined, foo()), 'foo', 'foo was added');
expect(dux.reducer(undefined, foo())).toEqual( 'foo');
await t.test('name as function', async (t) => {
});
test('setMutation, name as function', () => {
const bar = action('bar');
const dux = new Updux({
initial: '',
});
dux.setMutation(bar, () => () => 'bar');
t.equal(dux.reducer(undefined, bar()), 'bar', 'bar was added');
expect(dux.reducer(undefined, bar())).toEqual( 'bar');
});
});