Skip to content

Commit

Permalink
Refactored action ofType test to marble test #14
Browse files Browse the repository at this point in the history
  • Loading branch information
anton164 committed Oct 2, 2019
1 parent 5232135 commit c96d505
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/operators/operators.tests.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { equal, deepEqual } from 'assert';
import { of, OperatorFunction } from 'rxjs';
import { of, OperatorFunction, Scheduler } from 'rxjs';
import { reduce } from 'rxjs/operators';
import { TestScheduler } from 'rxjs/testing';
import { ActionWithPayload, ActionWithoutPayload } from 'rxbeach';
import { extractPayload, ofType } from 'rxbeach/operators';
import { mockAction } from 'rxbeach/internal';
import { withNamespace } from './operators';

const testScheduler = new TestScheduler((actual, expected) => {
deepEqual(actual, expected);
});

const pipeActionWithPayload = <P, R>(
payload: P,
pipe: OperatorFunction<ActionWithPayload<P>, R>
Expand All @@ -32,19 +37,23 @@ describe('operators', function() {
});

describe('ofType', function() {
it('Should filter one action type', async function() {
it('Should filter one action type', function() {
const targetType = 'Correct type';
const otherType = 'Wrong type';

const res = await of<ActionWithoutPayload>(
mockAction(targetType),
mockAction(otherType),
mockAction(targetType)
)
.pipe(ofType(targetType))
.toPromise();
const actionMarbles = {
a: mockAction(targetType),
b: mockAction(otherType),
};

equal(res.type, targetType);
testScheduler.run(({ hot, expectObservable }) => {
const filteredActions = hot<ActionWithoutPayload>(
'aba',
actionMarbles
).pipe(ofType(targetType));

expectObservable(filteredActions).toBe('a-a', actionMarbles);
});
});

it('Should filter multiple action types', async function() {
Expand Down

0 comments on commit c96d505

Please sign in to comment.