I am trying to figure out how to structure a jest unit test for the following:
I have a bunch of existing observables and subjects I want to test in a project. So I have started off with what I would assume to be a simple test case using RXjs marbles inside jest:
const testScheduler = new TestScheduler((actual, expected) => {
expect(actual).toEqual(expected);
});
testScheduler.run(({cold, expectObservable}) => {
const inputSubject = new Subject();
const outputSubject = new Subject();
inputSubject.pipe(map(val => val * 2)).subscribe(outputSubject);
cold('a|', {a:1}).subscribe(inputSubject);
expectObservable(outputSubject).toBe('a|', {a:2});
});
}
While this test does run, it fails. I am having trouble understanding the output from the test run. I would like to know if I am doing something wrong, or if I am misunderstanding things in general incorrectly. Or perhaps just some explanation of the output would be helpful.
- Expected
+ Received
@@ -1,16 +1,7 @@
Array [
Object {
- "frame": 0,
- "notification": Notification {
- "error": undefined,
- "hasValue": true,
- "kind": "N",
- "value": 2,
- },
- },
- Object {
"frame": 1,
"notification": Notification {
"error": undefined,
"hasValue": false,
"kind": "C",
...... the code ......
at TestScheduler.assertDeepEqual (common/chat/newMessages/ratifiedSendMessages/twilioRatifiedSendMessages.unit.test.js:27:24)
at node_modules/rxjs/src/internal/testing/TestScheduler.ts:159:14
at Array.filter (<anonymous>)
at TestScheduler.Object.<anonymous>.TestScheduler.flush (node_modules/rxjs/src/internal/testing/TestScheduler.ts:157:39)
at TestScheduler.run (node_modules/rxjs/src/internal/testing/TestScheduler.ts:392:12)
at Object.<anonymous> (common/chat/newMessages/ratifiedSendMessages/twilioRatifiedSendMessages.unit.test.js:30:21)