Skip to content

Commit

Permalink
test: Increased the coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mnasyrov committed Jul 25, 2021
1 parent ec3073e commit 94370f5
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions packages/rx-effects/src/stateEffects.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Subject } from 'rxjs';
import { createAction } from './action';
import { createEffect } from './effect';
import {
Expand Down Expand Up @@ -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<number>(0);
const sumAction = createAction<number>();

Expand All @@ -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<number>(0);
const sumAction = new Subject<number>();

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<number>();

Expand All @@ -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<number>();

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 });
});
});

0 comments on commit 94370f5

Please sign in to comment.