From 94370f51723ba21d653a17bbbffd45677793992c Mon Sep 17 00:00:00 2001 From: Mikhail Nasyrov Date: Sun, 25 Jul 2021 09:30:07 +0700 Subject: [PATCH] test: Increased the coverage --- packages/rx-effects/src/stateEffects.test.ts | 42 +++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/packages/rx-effects/src/stateEffects.test.ts b/packages/rx-effects/src/stateEffects.test.ts index d076e5e..4fee9c7 100644 --- a/packages/rx-effects/src/stateEffects.test.ts +++ b/packages/rx-effects/src/stateEffects.test.ts @@ -1,3 +1,4 @@ +import { Subject } from 'rxjs'; import { createAction } from './action'; import { createEffect } from './effect'; import { @@ -58,7 +59,7 @@ describe('createResetStoreEffect()', () => { }); describe('withStore()', () => { - it('should create an effect which passes an event and currnt state to the handler', () => { + it('should create an effect with an action which passes an event and currnt state to the handler', () => { const store = createStore(0); const sumAction = createAction(); @@ -73,10 +74,26 @@ describe('withStore()', () => { sumAction(5); expect(store.get()).toBe(8); }); + + it('should create an effect with an observable which passes an event and currnt state to the handler', () => { + const store = createStore(0); + const sumAction = new Subject(); + + const sumEffect = createEffect<[number, number]>(([arg, value]) => + store.set(arg + value), + ); + sumEffect.handle(withStore(sumAction, store)); + + sumAction.next(3); + expect(store.get()).toBe(3); + + sumAction.next(5); + expect(store.get()).toBe(8); + }); }); describe('withQuery()', () => { - it('should create an effect which passes an event and currnt state to the handler', () => { + it('should create an effect with action which passes an event and currnt state to the handler', () => { const store = createStore({ value: 0 }); const sumAction = createAction(); @@ -96,4 +113,25 @@ describe('withQuery()', () => { sumAction(5); expect(store.get()).toEqual({ value: 8 }); }); + + it('should create an effect with an observable which passes an event and currnt state to the handler', () => { + const store = createStore({ value: 0 }); + const sumAction = new Subject(); + + const sumEffect = createEffect<[number, number]>(([arg, prevValue]) => + store.set({ value: arg + prevValue }), + ); + sumEffect.handle( + withQuery( + sumAction, + store.query((state) => state.value), + ), + ); + + sumAction.next(3); + expect(store.get()).toEqual({ value: 3 }); + + sumAction.next(5); + expect(store.get()).toEqual({ value: 8 }); + }); });