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

Remove Subject.create, refactor WebSocketSubject #7381

Merged
merged 15 commits into from Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
126 changes: 0 additions & 126 deletions packages/rxjs/spec/Subject-spec.ts
@@ -1,6 +1,5 @@
import { expect } from 'chai';
import { Subject, Observable, AsyncSubject, Observer, of, config, Subscription, Subscriber, noop, operate } from 'rxjs';
import { AnonymousSubject } from 'rxjs/internal/Subject';
import { delay } from 'rxjs/operators';
import { TestScheduler } from 'rxjs/testing';
import { observableMatcher } from './helpers/observableMatcher';
Expand Down Expand Up @@ -448,104 +447,6 @@ describe('Subject', () => {
expect(subject.observed).to.equal(false);
});

it('should have a static create function that works', () => {
jakovljevic-mladen marked this conversation as resolved.
Show resolved Hide resolved
expect(Subject.create).to.be.a('function');
const source = of(1, 2, 3, 4, 5);
const nexts: number[] = [];
const output: any[] = [];

let error: any;
let complete = false;
let outputComplete = false;

const destination = {
closed: false,
next: function (x: number) {
nexts.push(x);
},
error: function (err: any) {
error = err;
this.closed = true;
},
complete: function () {
complete = true;
this.closed = true;
},
};

const sub: Subject<any> = Subject.create(destination, source);

sub.subscribe({
next: function (x: number) {
output.push(x);
},
complete: () => {
outputComplete = true;
},
});

sub.next('a');
sub.next('b');
sub.next('c');
sub.complete();

expect(nexts).to.deep.equal(['a', 'b', 'c']);
expect(complete).to.be.true;
expect(error).to.be.a('undefined');

expect(output).to.deep.equal([1, 2, 3, 4, 5]);
expect(outputComplete).to.be.true;
});

it('should have a static create function that works also to raise errors', () => {
jakovljevic-mladen marked this conversation as resolved.
Show resolved Hide resolved
expect(Subject.create).to.be.a('function');
const source = of(1, 2, 3, 4, 5);
const nexts: number[] = [];
const output: number[] = [];

let error: any;
let complete = false;
let outputComplete = false;

const destination = {
closed: false,
next: function (x: number) {
nexts.push(x);
},
error: function (err: any) {
error = err;
this.closed = true;
},
complete: function () {
complete = true;
this.closed = true;
},
};

const sub: Subject<any> = Subject.create(destination, source);

sub.subscribe({
next: function (x: number) {
output.push(x);
},
complete: () => {
outputComplete = true;
},
});

sub.next('a');
sub.next('b');
sub.next('c');
sub.error('boom');

expect(nexts).to.deep.equal(['a', 'b', 'c']);
expect(complete).to.be.false;
expect(error).to.equal('boom');

expect(output).to.deep.equal([1, 2, 3, 4, 5]);
expect(outputComplete).to.be.true;
});

it('should be an Observer which can be given to Observable.subscribe', (done) => {
const source = of(1, 2, 3, 4, 5);
const subject = new Subject<number>();
Expand Down Expand Up @@ -781,30 +682,3 @@ describe('Subject', () => {
expect(results).to.deep.equal([1, 1, 2, 2, 'complete']);
});
});

describe('AnonymousSubject', () => {
jakovljevic-mladen marked this conversation as resolved.
Show resolved Hide resolved
it('should be exposed', () => {
expect(AnonymousSubject).to.be.a('function');
});

it('should not be eager', () => {
let subscribed = false;

const subject = Subject.create(
null,
new Observable((observer: Observer<any>) => {
subscribed = true;
const subscription = of('x').subscribe(observer);
return () => {
subscription.unsubscribe();
};
})
);

const observable = subject.asObservable();
expect(subscribed).to.be.false;

observable.subscribe();
expect(subscribed).to.be.true;
});
});