ReactiveX / ReactiveX/rxjs

throwError with a falsy value is not equal to undefined in Marble Testing with TestCheduler

Open
#5,555 2 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.