Skip to content

Commit

Permalink
fix(operators): added error test case
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanGerbeth committed Nov 27, 2024
1 parent 236fb2e commit 8495596
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions packages/operators/src/log.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { from } from 'rxjs';
import { from, map } from 'rxjs';
import { TestScheduler } from 'rxjs/testing';
import { afterAll, beforeEach, describe, expect, test, vi } from 'vitest';

import { log, logResult } from './log';
import { enableLog, log, logResult } from './log';

describe('log', () => {
let testScheduler;
Expand All @@ -23,16 +23,18 @@ describe('log', () => {
};

const triggerVal = {
a: expectedVal.a,
b: expectedVal.b,
c: expectedVal.c
a: () => expectedVal.a,
b: () => expectedVal.b,
c: () => expectedVal.c,
d: () => {
throw new Error('custom error');
}
};

const expected = [
' operators:log:default content a',
' operators:log:default content b',
' operators:log:default content c',
' operators:log:default complete!'
' operators:log:default content c'
];

const actual = [];
Expand All @@ -41,9 +43,13 @@ describe('log', () => {
return v;
});

enableLog('operators:log:default');
testScheduler.run(({ cold, expectObservable, flush }) => {
const stream = cold('a-b-c|', triggerVal).pipe(log('operators:log:default'));
expectObservable(stream).toBe('a-b-c|', expectedVal);
const stream = cold('a-b-c-d|', triggerVal).pipe(
map(v => v()),
log('operators:log:default')
);
expectObservable(stream).toBe('a-b-c-#', expectedVal, new Error('custom error'));
flush();
expect(actual).deep.equal(expected);

Check failure on line 54 in packages/operators/src/log.test.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

src/log.test.js > log > default

AssertionError: expected [ …(3) ] to deeply equal [ …(3) ] - Expected + Received Array [ - " operators:log:default content a", - " operators:log:default content b", - " operators:log:default content c", + "2024-11-27T19:11:41.452Z operators:log:default content a", + "2024-11-27T19:11:41.452Z operators:log:default content b", + "2024-11-27T19:11:41.452Z operators:log:default content c", ] ❯ src/log.test.js:54:27 ❯ TestScheduler.run ../../node_modules/rxjs/src/internal/testing/TestScheduler.ts:678:19 ❯ src/log.test.js:47:19
});
Expand All @@ -65,6 +71,7 @@ describe('log', () => {

const triggerVal = ['content a', 'content b', 'content c'];

enableLog('operators:log:result');
await logResult('operators:log:result', from(triggerVal));
expect(actual).deep.equal(expectedVal);

Check failure on line 76 in packages/operators/src/log.test.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

src/log.test.js > log > logResult

AssertionError: expected [ …(4) ] to deeply equal [ …(4) ] - Expected + Received Array [ - " operators:log:result content a", - " operators:log:result content b", - " operators:log:result content c", - " operators:log:result complete!", + "2024-11-27T19:11:41.475Z operators:log:result content a", + "2024-11-27T19:11:41.475Z operators:log:result content b", + "2024-11-27T19:11:41.475Z operators:log:result content c", + "2024-11-27T19:11:41.475Z operators:log:result complete!", ] ❯ src/log.test.js:76:25
});
Expand Down

0 comments on commit 8495596

Please sign in to comment.