Skip to content

Commit

Permalink
chore(subject): test error after complete, etc. (#4351)
Browse files Browse the repository at this point in the history
Add remaining variations: should not error after complete, etc.
  • Loading branch information
cartant authored and benlesh committed Jan 29, 2019
1 parent b90d1bc commit 2a8050a
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion src/internal/Subject-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,17 +426,60 @@ describe('Subject', () => {
expect(results).to.deep.equal(['a', 'C']);
});

it('should not next after error', () => {
it('should not error after completed', () => {
const error = new Error('wut?');
const subject = new Subject<string>();
const results: (string|Error)[] = [];
subject.subscribe(x => results.push(x), (err) => results.push(err), () => results.push('C'));
subject.next('a');
subject.complete();
subject.error(error);
expect(results).to.deep.equal(['a', 'C']);
});

it('should not complete after completed', () => {
const subject = new Subject<string>();
const results: string[] = [];
subject.subscribe(x => results.push(x), null, () => results.push('C'));
subject.next('a');
subject.complete();
subject.complete();
expect(results).to.deep.equal(['a', 'C']);
});

it('should not next after error', () => {
const error = new Error('wut?');
const subject = new Subject<string>();
const results: (string|Error)[] = [];
subject.subscribe(x => results.push(x), (err) => results.push(err));
subject.next('a');
subject.error(error);
subject.next('b');
expect(results).to.deep.equal(['a', error]);
});

it('should not error after error', () => {
const error = new Error('wut?');
const subject = new Subject<string>();
const results: (string|Error)[] = [];
subject.subscribe(x => results.push(x), (err) => results.push(err));
subject.next('a');
subject.error(error);
subject.error(error);
expect(results).to.deep.equal(['a', error]);
});

it('should not complete after error', () => {
const error = new Error('wut?');
const subject = new Subject<string>();
const results: (string|Error)[] = [];
subject.subscribe(x => results.push(x), (err) => results.push(err), () => results.push('C'));
subject.next('a');
subject.error(error);
subject.complete();
expect(results).to.deep.equal(['a', error]);
});

describe('asObservable', () => {
it('should hide subject', () => {
const subject = new Subject();
Expand Down

0 comments on commit 2a8050a

Please sign in to comment.