jest-marbles icon indicating copy to clipboard operation
jest-marbles copied to clipboard

`toBeObservable` does not work with with Ngrx `mockStore.overrideSelector`

Open Itrulia opened this issue 3 years ago • 3 comments

While upgrading our repository from Nx 11.x & Angular 11.x to Nx 13.1.4 and Angular to v12.x we noticed all of our expect(result).toBeObservable(expected) that used store.overrideSelector started to fail. We narrowed it down to jest-marbles not properly working anymore.

Reproduction and more information can be found in this repository: https://github.com/Itrulia/jest-marbles-ngrx-bug

Itrulia avatar Nov 16 '21 13:11 Itrulia

I think we ran into the same bug. What I had drilled this down to, was the jest runner being used. At some point, that switched from jest-jasmine2 to jest-circus.

If you set testRunner: 'jest-jasmine2' in jest.preset.js, your tests should succeed again.

But your details here, might help solve the underlying issue.

schmkr avatar Nov 19 '21 18:11 schmkr

If you set testRunner: 'jest-jasmine2' in jest.preset.js, your tests should succeed again.

We already have this in our jest.preset.js and are experiencing this issue.

To add to this, the import order in the test file is significant. This only seems to happen when the jest-marbles import (or the import of another module which imports jest-marbles), is above the import from @ngrx/store/testing.

Works

import { MockStore, provideMockStore } from '@ngrx/store/testing';
import { cold, hot } from 'jest-marbles';
import { MockStore, provideMockStore } from '@ngrx/store/testing';
import { foo } from 'module-importing-jest-marbles';

Fails

import { cold, hot } from 'jest-marbles';
import { MockStore, provideMockStore } from '@ngrx/store/testing';
import { foo } from 'module-importing-jest-marbles';
import { MockStore, provideMockStore } from '@ngrx/store/testing';

Idicious avatar Jan 17 '22 13:01 Idicious

I think we ran into the same bug. What I had drilled this down to, was the jest runner being used. At some point, that switched from jest-jasmine2 to jest-circus.

If you set testRunner: 'jest-jasmine2' in jest.preset.js, your tests should succeed again.

But your details here, might help solve the underlying issue.

Thank you so much. I was struggling with it for many days during dependencies upgrade. I also tried to use jasmine-marbles since it supports jest-circus, however, some of my tests were still failing, so enforcing using the jest-jasmine2 test runner solved the issue with failing marble tests.

pavelrazuvalau avatar Dec 22 '22 09:12 pavelrazuvalau