2

If I run all tests for one epic at once only the first test passes. The other tests fail because the frame differs. But every test singly run passes.

I could not find any related problem to this nether found something in the RxJS not the redux observable docs. I thought there could be some kind of a reset function on the TestScheduler but there isn't.

One of my test (they all look pretty simular):

test('should fail if e-mail is missing', () => {
    testScheduler.run(({ hot, expectObservable }) => {
        const action$ = new ActionsObservable(
            hot('-a', {
                a: login('', 'secret')
            })
        );

        const output$ = epic(action$, null, null);

        expectObservable(output$).toBe('-a', {
            a: failure(
                formErrors.credentialsEmpty(['email', 'password'])
            )
        });
    });
});

I expect the frame of output marble to be 1 but it is 2. The output of a failing test:

Array [
        Object {
    -     "frame": 1,
    +     "frame": 2,
          "notification": Notification {
            "error": undefined,
            "hasValue": true,
            "kind": "N",
            "value": Object {

edit

I could get around that behaviour by creating one TestScheduler instance per test but I am not sure if I am supposed to do it this way.

Liam
  • 27,717
  • 28
  • 128
  • 190
Finn
  • 23
  • 5

1 Answers1

3

Stumbled across this today. I think creating one new TestScheduler per test is probably a good idea. It doesn't seem to have a noticeable impact between tests - and that way you're sure that the state is reset between tests.

One other workaround is to do testScheduler.frame = 0 in a beforeEach - but I opted to just create it from scratch each time.

mbdavis
  • 3,861
  • 2
  • 22
  • 42
  • Yes I only noticed it after many minutes of head scratching that my first test would work, and the second test would be off by exactly double the number of frames....not immediately clear! – mbdavis Aug 05 '20 at 20:35
  • Jest seems to cause this problem. When using Jasmine the frame is reset, in jest (for some reason) it's not – Liam Jul 01 '21 at 07:42