ngrx + marble testing + delay
Asked Answered
S

1

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. 
Seventy answered 28/11, 2018 at 13:32 Comment(2)
This is a very similar question #53428465. You basically have to pass scheduler to delayRobedechambre
Thanks, that's what I needed.Seventy
B
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 });
})
Babara answered 2/12, 2018 at 12:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.