throwError with a falsy value is not equal to undefined in Marble Testing with TestCheduler
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 31.7k
- Forks
- 3k
- PR merge metrics
- No merged PRs in 30d
Description
Bug Report
Current Behavior
Marble testing with throwError(undefined) should return an Observable with *.notification.error equals to the value passed into throwError constructor itself, but it's expected to a default string called 'error' currently.
Expected $[0].notification.error = undefined to equal 'error'.
Reproduction
My function to be test shows here:
// util.ts
import { Observable, throwError } from 'rxjs';
const securedErrorHandler = (obj) => {
return err => {
return throwError(obj);
};
}
The unit test file shows:
// util.spec.ts
import { throwError } from 'rxjs';
import { TestScheduler } from 'rxjs/testing';
import { securedErrorHandler } from './util';
describe('securedErrorHandler', () => {
const expectedMarbles = '#';
let scheduler: TestScheduler;
beforeEach(() => {
scheduler = new TestScheduler((actual, expected) => {
expect(actual).toEqual(expected);
});
});
it('#securedErrorHandler should construct an error if input error is not an instance of Observable', () => {
scheduler.run(({ expectObservable }) => {
const result$ = securedErrorHandler(undefined);
expectObservable(result$).toBe(expectedMarbles, null, undefined);
});
}
}
Expected behavior
Unit test should get passed.
Environment
- Runtime: Latest Chrome
- RxJS version: 6.5.3
Possible Solution
I found following logic in https://github.com/ReactiveX/rxjs/blob/fd66c2937ef73172d512f56b4c868e75a78635ab/src/internal/testing/TestScheduler.ts#L353
It will set error value to 'error' when passed in errorValue is a falsy value. Is there any consideration about it, I think it should be removed or be documented in RxJs docs.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect src/internal/testing/TestScheduler.ts at the referenced logic that assigns the marble error value, then run the reproduction using TestScheduler and throwError(undefined). Confirm that falsy values, including undefined, remain equal to the value passed to throwError, and add or update a focused test showing the expected notification error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100