9

Let's say I have an effect

@Effect()
someEffect$ = this.actions$.pipe(ofType(X), switchMap(() => 
of(Y).pipe(delay(3000)))

How should marble test look like?

const action = new X();
const result = new Y();

actions$.stream = hot('-x', { x: action });
const expected = cold('-y', { y: result }); // ? adding frames or 3s doesn't work
expect(effects.someEffect$).toBeObservable(expected);

In return I get

Expected $.lenght = 0 to equal 1. 
Cor Kalom
  • 91
  • 2
  • 2
    This is a very similar question https://stackoverflow.com/questions/53427965/react-redux-observable-timeout-marble-testing. You basically have to pass scheduler to `delay` – martin Nov 28 '18 at 16:15
  • Thanks, that's what I needed. – Cor Kalom Nov 28 '18 at 20:08

1 Answers1

9

If you dont want to pass scheduler to delay you can also do sth like:

import { cold, hot, getTestScheduler } from "jasmine-marbles";

const scheduler = getTestScheduler();
scheduler.run(helpers => {
  const action = new X();
  const result = new Y();

  actions$ = helpers.hot('-x', { x: action });
  helpers.expectObservable(effects.someEffect$).toBe('- 3s y', { y: result });
})
Miroslav Jonas
  • 5,407
  • 1
  • 27
  • 41
bys
  • 234
  • 2
  • 8