I found that rxjs marbles tests failed on jest esm when using time-related(e,g. delay
) operators.
Check the test case here: https://github.com/jaohaohsuan/jest-preset-angular/commit/259b2361d37609e8a409bce96c953603739ef1cb
Does anyone have this issue?
I am using the example-app-v14 sample project as the test environment.
yarn run test
was passed, but yarn run test-esm
didn't.
The moduleNameMapper of jest-esm.config.mjs
file:
moduleNameMapper: {
tslib: 'tslib/tslib.es6.js',
"^rxjs(/operators)?$": '<rootDir>/node_modules/rxjs/dist/bundles/rxjs.umd.js',
"^rxjs/testing":
"<rootDir>node_modules/rxjs/dist/cjs/testing/index.js",
},
The Jest test results:
FAIL src/app/issues/rxjs-marbles.spec.ts
Rxjs marbles
✕ generates the stream correctly with delay 2s (12 ms)
✓ generates the stream correctly without delay (1 ms)
● Rxjs marbles › generates the stream correctly with delay 2s
expect(received).toEqual(expected) // deep equality
- Expected - 26
+ Received + 1
- Array [
- Object {
- "frame": 5,
- "notification": Object {
- "error": undefined,
- "kind": "N",
- "value": "a",
- },
- },
- Object {
- "frame": 8,
- "notification": Object {
- "error": undefined,
- "kind": "N",
- "value": "b",
- },
- },
- Object {
- "frame": 9,
- "notification": Object {
- "error": undefined,
- "kind": "C",
- "value": undefined,
- },
- },
- ]
+ Array []
8 | beforeEach(() => {
9 | testScheduler = new TestScheduler((actual, expected) => {
> 10 | expect(actual).toEqual(expected);
| ^
11 | });
12 | });
13 |
at TestScheduler.assertDeepEqual (src/app/issues/rxjs-marbles.spec.ts:10:22)
at Array.filter (<anonymous>)
at src/app/issues/rxjs-marbles.spec.ts:15:19
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 passed, 2 total
Snapshots: 0 total
Time: 2.519 s
Thanks :)