Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error rework #4765

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions spec/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ describe('index', () => {
expect(index.ObjectUnsubscribedError).to.exist;
expect(index.UnsubscriptionError).to.exist;
expect(index.TimeoutError).to.exist;

expect(index.isOutOfRangeError).to.exist;
expect(index.isEmptyError).to.exist;
expect(index.isObjectUnsubscribedError).to.exist;
expect(index.isTeardownError).to.exist;
expect(index.isTimeoutError).to.exist;
});

it('should export constants', () => {
Expand Down
45 changes: 31 additions & 14 deletions spec/operators/elementAt-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { expect } from 'chai';
import { elementAt, mergeMap } from 'rxjs/operators';
import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing';
import { ArgumentOutOfRangeError, of, range } from 'rxjs';
import { of, range, isOutOfRangeError } from 'rxjs';
import { createOutOfRangeError } from 'rxjs/internal/util/ArgumentOutOfRangeError';

declare function asDiagram(arg: string): Function;

Expand All @@ -12,7 +13,7 @@ describe('elementAt operator', () => {
const subs = '^ ! ';
const expected = '--------(c|) ';

expectObservable((<any>source).pipe(elementAt(2))).toBe(expected);
expectObservable(source.pipe(elementAt(2))).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
});

Expand All @@ -21,7 +22,7 @@ describe('elementAt operator', () => {
const subs = '^ !';
const expected = '--(a|)';

expectObservable((<any>source).pipe(elementAt(0))).toBe(expected);
expectObservable(source.pipe(elementAt(0))).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
});

Expand All @@ -30,7 +31,7 @@ describe('elementAt operator', () => {
const subs = '^ !';
const expected = '-----------(d|)';

expectObservable((<any>source).pipe(elementAt(3))).toBe(expected);
expectObservable(source.pipe(elementAt(3))).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
});

Expand All @@ -39,7 +40,7 @@ describe('elementAt operator', () => {
const subs = '^ !';
const expected = '--------(c|)';

expectObservable((<any>source).pipe(elementAt(2))).toBe(expected);
expectObservable(source.pipe(elementAt(2))).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
});

Expand All @@ -48,7 +49,7 @@ describe('elementAt operator', () => {
const subs = '(^!)';
const expected = '#';

expectObservable((<any>source).pipe(elementAt(0))).toBe(expected, undefined, new ArgumentOutOfRangeError());
expectObservable(source.pipe(elementAt(0))).toBe(expected, undefined, createOutOfRangeError());
expectSubscriptions(source.subscriptions).toBe(subs);
});

Expand All @@ -57,7 +58,7 @@ describe('elementAt operator', () => {
const subs = '(^!)';
const expected = '#';

expectObservable((<any>source).pipe(elementAt(0))).toBe(expected);
expectObservable(source.pipe(elementAt(0))).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
});

Expand All @@ -66,7 +67,7 @@ describe('elementAt operator', () => {
const subs = '^';
const expected = '-';

expectObservable((<any>source).pipe(elementAt(0))).toBe(expected);
expectObservable(source.pipe(elementAt(0))).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
});

Expand All @@ -76,7 +77,7 @@ describe('elementAt operator', () => {
const expected = '------- ';
const unsub = ' ! ';

const result = (<any>source).pipe(elementAt(2));
const result = source.pipe(elementAt(2));

expectObservable(result, unsub).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
Expand All @@ -88,7 +89,7 @@ describe('elementAt operator', () => {
const expected = '------- ';
const unsub = ' ! ';

const result = (<any>source).pipe(
const result = source.pipe(
mergeMap((x: any) => of(x)),
elementAt(2),
mergeMap((x: any) => of(x))
Expand All @@ -99,20 +100,36 @@ describe('elementAt operator', () => {
});

it('should throw if index is smaller than zero', () => {
expect(() => { range(0, 10).pipe(elementAt(-1)); })
.to.throw(ArgumentOutOfRangeError);
try {
range(0, 10).pipe(elementAt(-1));
} catch (err) {
expect(isOutOfRangeError(err)).to.be.true;
return;
}
expect('').to.equal('it should not get here');
});

it('should raise error if index is out of range but does not have default value', () => {
const source = hot('--a--|');
const subs = '^ !';
const expected = '-----#';

expectObservable((<any>source).pipe(elementAt(3)))
.toBe(expected, null, new ArgumentOutOfRangeError());
expectObservable(source.pipe(elementAt(3)))
.toBe(expected, null, createOutOfRangeError());
expectSubscriptions(source.subscriptions).toBe(subs);
});

it('should raise an out of range error if the index if out of range and there is no default value', () => {
of(0, 1, 2).pipe(
elementAt(3),
)
.subscribe({
error: err => {
expect(isOutOfRangeError(err)).to.be.true;
}
});
});

it('should return default value if index is out of range', () => {
const source = hot('--a--|');
const subs = '^ !';
Expand Down
7 changes: 4 additions & 3 deletions spec/operators/first-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { expect } from 'chai';
import { hot, expectObservable, expectSubscriptions } from '../helpers/marble-testing';
import { first, mergeMap, delay } from 'rxjs/operators';
import { TestScheduler } from 'rxjs/testing';
import { of, from, Observable, Subject, EmptyError } from 'rxjs';
import { of, from, Observable, Subject } from 'rxjs';
import { createEmptyError } from 'rxjs/internal/util/EmptyError';

declare function asDiagram(arg: string): Function;

Expand Down Expand Up @@ -33,7 +34,7 @@ describe('Observable.prototype.first', () => {
const expected = '-----#';
const sub = '^ !';

expectObservable(e1.pipe(first())).toBe(expected, null, new EmptyError());
expectObservable(e1.pipe(first())).toBe(expected, null, createEmptyError());
expectSubscriptions(e1.subscriptions).toBe(sub);
});

Expand Down Expand Up @@ -141,7 +142,7 @@ describe('Observable.prototype.first', () => {
const expected = '---------------#';
const sub = '^ !';

expectObservable(e1.pipe(first(x => x === 's'))).toBe(expected, null, new EmptyError());
expectObservable(e1.pipe(first(x => x === 's'))).toBe(expected, null, createEmptyError());
expectSubscriptions(e1.subscriptions).toBe(sub);
});

Expand Down
7 changes: 4 additions & 3 deletions spec/operators/last-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing';
import { last, mergeMap } from 'rxjs/operators';
import { EmptyError, of, from, Observable } from 'rxjs';
import { of, from, Observable } from 'rxjs';
import { createEmptyError } from 'rxjs/internal/util/EmptyError';

declare function asDiagram(arg: string): Function;

Expand All @@ -21,7 +22,7 @@ describe('Observable.prototype.last', () => {
const e1subs = '^ !';
const expected = '-----#';

expectObservable(e1.pipe(last())).toBe(expected, null, new EmptyError());
expectObservable(e1.pipe(last())).toBe(expected, null, createEmptyError());
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

Expand All @@ -30,7 +31,7 @@ describe('Observable.prototype.last', () => {
const e1subs = '(^!)';
const expected = '#';

expectObservable(e1.pipe(last())).toBe(expected, null, new EmptyError());
expectObservable(e1.pipe(last())).toBe(expected, null, createEmptyError());
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

Expand Down
7 changes: 4 additions & 3 deletions spec/operators/single-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { expect } from 'chai';
import { hot, expectObservable, expectSubscriptions } from '../helpers/marble-testing';
import { single, mergeMap, tap } from 'rxjs/operators';
import { of, EmptyError } from 'rxjs';
import { of } from 'rxjs';
import { createEmptyError } from 'rxjs/internal/util/EmptyError';

declare function asDiagram(arg: string): Function;

Expand All @@ -22,7 +23,7 @@ describe('single operator', () => {
const e1subs = '^ !';
const expected = '---#';

expectObservable(e1.pipe(single())).toBe(expected, null, new EmptyError());
expectObservable(e1.pipe(single())).toBe(expected, null, createEmptyError());
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

Expand Down Expand Up @@ -134,7 +135,7 @@ describe('single operator', () => {
return value === 'a';
};

expectObservable(e1.pipe(single(predicate))).toBe(expected, null, new EmptyError());
expectObservable(e1.pipe(single(predicate))).toBe(expected, null, createEmptyError());
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

Expand Down
11 changes: 8 additions & 3 deletions spec/operators/skipLast-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing';
import { skipLast, mergeMap } from 'rxjs/operators';
import { range, ArgumentOutOfRangeError, of } from 'rxjs';
import { range, of, isOutOfRangeError } from 'rxjs';

declare function asDiagram(arg: string): Function;

Expand Down Expand Up @@ -135,8 +135,13 @@ describe('skipLast operator', () => {
});

it('should throw if total is less than zero', () => {
expect(() => { range(0, 10).pipe(skipLast(-1)); })
.to.throw(ArgumentOutOfRangeError);
try {
range(0, 10).pipe(skipLast(-1));
} catch (err) {
expect(isOutOfRangeError(err)).to.be.true;
return;
}
throw new Error('should not make it this far');
});

it('should not break unsubscription chain when unsubscribed explicitly', () => {
Expand Down
11 changes: 8 additions & 3 deletions spec/operators/take-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing';
import { take, mergeMap } from 'rxjs/operators';
import { range, ArgumentOutOfRangeError, of, Observable, Subject } from 'rxjs';
import { range, of, Observable, Subject, isOutOfRangeError } from 'rxjs';

declare function asDiagram(arg: string): Function;

Expand Down Expand Up @@ -108,8 +108,13 @@ describe('take operator', () => {
});

it('should throw if total is less than zero', () => {
expect(() => { range(0, 10).pipe(take(-1)); })
.to.throw(ArgumentOutOfRangeError);
try {
range(0, 10).pipe(take(-1));
} catch (err) {
expect(isOutOfRangeError(err)).to.be.true;
return;
}
throw new Error('should not make it this far');
});

it('should not break unsubscription chain when unsubscribed explicitly', () => {
Expand Down
11 changes: 8 additions & 3 deletions spec/operators/takeLast-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing';
import { takeLast, mergeMap } from 'rxjs/operators';
import { range, ArgumentOutOfRangeError, of } from 'rxjs';
import { range, of, isOutOfRangeError } from 'rxjs';

declare function asDiagram(arg: string): Function;

Expand Down Expand Up @@ -142,8 +142,13 @@ describe('takeLast operator', () => {
});

it('should throw if total is less than zero', () => {
expect(() => { range(0, 10).pipe(takeLast(-1)); })
.to.throw(ArgumentOutOfRangeError);
try {
range(0, 10).pipe(takeLast(-1));
} catch (err) {
expect(isOutOfRangeError(err)).to.be.true;
return;
}
throw new Error('should not reach this point');
});

it('should not break unsubscription chain when unsubscribed explicitly', () => {
Expand Down
5 changes: 3 additions & 2 deletions spec/operators/throwIfEmpty-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { expect } from 'chai';
import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing';
import { cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing';
import { EMPTY, of, EmptyError, defer, throwError } from 'rxjs';
import { throwIfEmpty, mergeMap, retry } from 'rxjs/operators';
import { createEmptyError } from 'rxjs/internal/util/EmptyError';

declare function asDiagram(arg: string): Function;

Expand Down Expand Up @@ -169,7 +170,7 @@ describe('throwIfEmpty', () => {
const expected = '----#';
expectObservable(
source.pipe(throwIfEmpty())
).toBe(expected, undefined, new EmptyError());
).toBe(expected, undefined, createEmptyError());
expectSubscriptions(source.subscriptions).toBe([sub1]);
});

Expand Down
3 changes: 2 additions & 1 deletion spec/operators/timeout-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/mar
import { timeout, mergeMap } from 'rxjs/operators';
import { TestScheduler } from 'rxjs/testing';
import { TimeoutError, of } from 'rxjs';
import { createTimeoutError } from 'rxjs/internal/util/TimeoutError';

declare function asDiagram(arg: string): Function;
declare const rxTestScheduler: TestScheduler;

/** @test {timeout} */
describe('timeout operator', () => {
const defaultTimeoutError = new TimeoutError();
const defaultTimeoutError = createTimeoutError();

asDiagram('timeout(50)')('should timeout after a specified timeout period', () => {
const e1 = cold('-------a--b--|');
Expand Down
2 changes: 1 addition & 1 deletion spec/util/ArgumentOutOfRangeError-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ describe('ArgumentOutOfRangeError', () => {
expect(error.name).to.be.equal('ArgumentOutOfRangeError');
});
it('Should have a message', () => {
expect(error.message).to.be.equal('argument out of range');
expect(error.message).to.be.equal('out of range');
});
});
8 changes: 8 additions & 0 deletions spec/util/EmptyError-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from 'chai';
import { EmptyError } from 'rxjs/util/EmptyError';
import { createEmptyError } from 'rxjs/internal/util/EmptyError';

/** @test {EmptyError} */
describe('EmptyError', () => {
Expand All @@ -11,3 +12,10 @@ describe('EmptyError', () => {
expect(error.message).to.be.equal('no elements in sequence');
});
});

describe('createEmptyError', () => {
const error = createEmptyError();
it('Should have a message', () => {
expect(error.message).to.be.equal('no elements in sequence');
});
});
8 changes: 8 additions & 0 deletions spec/util/ObjectUnsubscribedError-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from 'chai';
import { ObjectUnsubscribedError } from 'rxjs/util/ObjectUnsubscribedError';
import { createObjectUnsubscribedError } from 'rxjs/internal/util/ObjectUnsubscribedError';

/** @test {ObjectUnsubscribedError} */
describe('ObjectUnsubscribedError', () => {
Expand All @@ -11,3 +12,10 @@ describe('ObjectUnsubscribedError', () => {
expect(error.message).to.be.equal('object unsubscribed');
});
});

describe('createObjectUnsubscribedError', () => {
const error = createObjectUnsubscribedError();
it('Should have a message', () => {
expect(error.message).to.be.equal('object unsubscribed');
});
});
Loading