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

chore: update ignoreElements tests to run mode #5952

Merged
Merged
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
128 changes: 75 additions & 53 deletions spec/operators/ignoreElements-spec.ts
@@ -1,79 +1,101 @@
/** @prettier */
import { ignoreElements, mergeMap } from 'rxjs/operators';
import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing';
import { TestScheduler } from 'rxjs/testing';
import { of } from 'rxjs';
import { observableMatcher } from '../helpers/observableMatcher';

/** @test {ignoreElements} */
describe('ignoreElements operator', () => {
it('should ignore all the elements of the source', () => {
const source = hot('--a--b--c--d--|');
const subs = '^ !';
const expected = '--------------|';
describe('ignoreElements', () => {
let testScheduler: TestScheduler;

beforeEach(() => {
testScheduler = new TestScheduler(observableMatcher);
});

expectObservable(source.pipe(ignoreElements())).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
it('should ignore all the elements of the source', () => {
testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => {
const e1 = hot(' --a--b--c--d--|');
const e1subs = ' ^-------------!';
const expected = '--------------|';

expectObservable(e1.pipe(ignoreElements())).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
});

it('should allow unsubscribing early and explicitly', () => {
const source = hot('--a--b--c--d--|');
const subs = '^ ! ';
const expected = '-------- ';
const unsub = ' ! ';
testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => {
const e1 = hot(' --a--b--c--d--|');
const e1subs = ' ^------! ';
const expected = '-------- ';
const unsub = ' -------! ';

const result = source.pipe(ignoreElements());
const result = e1.pipe(ignoreElements());

expectObservable(result, unsub).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
expectObservable(result, unsub).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
});

it('should allow unsubscribing early and explicitly', () => {
const source = hot('--a--b--c--d--|');
const subs = '^ ! ';
const expected = '-------- ';
const unsub = ' ! ';

const result = source.pipe(
mergeMap((x: string) => of(x)),
ignoreElements(),
mergeMap((x: string) => of(x))
);

expectObservable(result, unsub).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
it('should allow unsubscribing early and explicitly with higher order', () => {
testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => {
const e1 = hot(' --a--b--c--d--|');
const e1subs = ' ^------! ';
const expected = '-------- ';
const unsub = ' -------! ';

const result = e1.pipe(
mergeMap((x) => of(x)),
ignoreElements(),
mergeMap((x) => of(x))
);

expectObservable(result, unsub).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
});

it('should propagate errors from the source', () => {
const source = hot('--a--#');
const subs = '^ !';
const expected = '-----#';

expectObservable(source.pipe(ignoreElements())).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => {
const e1 = hot(' --a--#');
const e1subs = ' ^----!';
const expected = '-----#';

expectObservable(e1.pipe(ignoreElements())).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
});

it('should support Observable.empty', () => {
const source = cold('|');
const subs = '(^!)';
const expected = '|';
it('should handle empty', () => {
testScheduler.run(({ cold, expectObservable, expectSubscriptions }) => {
const e1 = cold(' | ');
const e1subs = ' (^!)';
const expected = '| ';

expectObservable(source.pipe(ignoreElements())).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
expectObservable(e1.pipe(ignoreElements())).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
});

it('should support Observable.never', () => {
const source = cold('-');
const subs = '^';
const expected = '-';
it('should handle never', () => {
testScheduler.run(({ cold, expectObservable, expectSubscriptions }) => {
const e1 = cold(' -');
const e1subs = ' ^';
const expected = '-';

expectObservable(source.pipe(ignoreElements())).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
expectObservable(e1.pipe(ignoreElements())).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
});

it('should support Observable.throw', () => {
const source = cold('#');
const subs = '(^!)';
const expected = '#';
it('should handle throw', () => {
testScheduler.run(({ cold, expectObservable, expectSubscriptions }) => {
const e1 = cold(' # ');
const e1subs = ' (^!)';
const expected = '# ';

expectObservable(source.pipe(ignoreElements())).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
expectObservable(e1.pipe(ignoreElements())).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
});
});