From 2c26f9652b8543c8c7d499b076d39713c549bbc1 Mon Sep 17 00:00:00 2001 From: Yanick Champoux Date: Fri, 8 Oct 2021 11:46:19 -0400 Subject: [PATCH] add the test --- src/{selectors.test.ts => selectors.test.js} | 51 +++++++++----------- 1 file changed, 22 insertions(+), 29 deletions(-) rename src/{selectors.test.ts => selectors.test.js} (69%) diff --git a/src/selectors.test.ts b/src/selectors.test.js similarity index 69% rename from src/selectors.test.ts rename to src/selectors.test.js index 73ec7e9..918328c 100644 --- a/src/selectors.test.ts +++ b/src/selectors.test.js @@ -1,13 +1,14 @@ import { test } from 'tap'; -import Updux, { dux, coduxes, DuxState } from '.'; -import { expectType } from 'tsd'; + +import { Updux } from './Updux.js'; +import { action } from './actions.js'; test('basic selectors', async t => { - const updux = dux({ + const updux = new Updux({ subduxes: { - bogeys: dux({ + bogeys: new Updux({ selectors: { - bogey: (bogeys: any) => (id: string) => bogeys[id], + bogey: (bogeys) => (id) => bogeys[id], }, }), }, @@ -28,12 +29,15 @@ test('basic selectors', async t => { }); test('available in the middleware', async t => { - const updux = dux({ + const doIt = action('doIt'); + + const updux = new Updux({ + actions: { doIt }, subduxes: { - bogeys: dux({ + bogeys: new Updux({ initial: { enkidu: 'foo' }, selectors: { - bogey: (bogeys: any) => (id: string) => bogeys[id], + bogey: (bogeys) => (id) => bogeys[id], }, }), }, @@ -57,36 +61,27 @@ test('available in the middleware', async t => { }); test('selector typescript', async t => { - const bar = dux({ - initial: { baz: 1 } as { baz: number }, + const bar = new Updux({ + initial: { baz: 1 }, selectors: { - getBaz: (state: { baz: number }) => state.baz, + getBaz: (state) => state.baz, getStringBaz: state => `${state.baz}`, - getMultBaz: state => (mult: number) => state.baz * mult, + getMultBaz: state => (mult) => state.baz * mult, }, }); - expectType<{ - getBaz: Function; - getStringBaz: Function; - }>(bar.selectors); t.same(bar.selectors.getBaz(bar.initial), 1); t.same(bar.selectors.getMultBaz({ baz: 3 })(2), 6); test('subduxes', async t => { - const foo = dux({ + const foo = new Updux({ subduxes: { bar }, - ...coduxes( dux({}) ), selectors: { getRoot: () => 'root' } }); - expectType<{ - ({ bar: { baz: number } }): number; - }>(foo.selectors.getBaz); - t.same(foo.selectors.getBaz(foo.initial), 1); t.same(foo.selectors.getMultBaz({ bar: { baz: 3 } })(2), 6); @@ -94,10 +89,10 @@ test('selector typescript', async t => { }); test('no root selector', async t => { - const foo = dux({ + const foo = new Updux({ subduxes: { - quux: dux({}), - bar: dux({ + quux: new Updux({}), + bar: new Updux({ selectors: { getBaz: () => 'baz' } @@ -114,14 +109,14 @@ test('selector in mw', async () => { { initial: { stuff: 12 }, subduxes: { - bar: dux({ + bar: new Updux({ initial: 'potato', selectors: { getBar: () => 'meh' } }) }, selectors: { // TODO here we should auto-populate the state - getStuff: (state: {stuff: number}) => state.stuff + getStuff: (state) => state.stuff } } ); @@ -129,7 +124,5 @@ test('selector in mw', async () => { myDux.addEffect( '*', ({ selectors, getState }) => () => () => { - expectType>( getState() ); - expectType<(...args:any[]) => number>(selectors.getStuff); }); });