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(test): use fakeTimers with setTimeout in buffer, skipUntil and window #7392

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 packages/rxjs/spec/operators/buffer-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { EMPTY, NEVER, throwError, of, Subject, interval } from 'rxjs';
import { TestScheduler } from 'rxjs/testing';
import { observableMatcher } from '../helpers/observableMatcher';
import { expect } from 'chai';
import * as sinon from 'sinon';

/** @test {buffer} */
describe('Observable.prototype.buffer', () => {
Expand Down Expand Up @@ -325,6 +326,8 @@ describe('Observable.prototype.buffer', () => {
});

it('should buffer when Promise resolves', (done) => {
const sandbox = sinon.createSandbox();
const fakeTimers = sandbox.useFakeTimers();
const e1 = interval(3).pipe(take(5));
const expected = [
[0, 1],
Expand All @@ -338,9 +341,12 @@ describe('Observable.prototype.buffer', () => {
error: () => done(new Error('should not be called')),
complete: () => {
expect(expected.length).to.equal(0);
sandbox.restore();
done();
},
});

fakeTimers.tickAsync(15);
});

it('should raise error when Promise rejects', (done) => {
Expand Down
6 changes: 6 additions & 0 deletions packages/rxjs/spec/operators/skipUntil-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { skipUntil, mergeMap, take } from 'rxjs/operators';
import { asInteropObservable } from '../helpers/interop-helper';
import { TestScheduler } from 'rxjs/testing';
import { observableMatcher } from '../helpers/observableMatcher';
import * as sinon from 'sinon';

/** @test {skipUntil} */
describe('skipUntil', () => {
Expand Down Expand Up @@ -369,6 +370,8 @@ describe('skipUntil', () => {
});

it('should skip until Promise resolves', (done) => {
const sandbox = sinon.createSandbox();
const fakeTimers = sandbox.useFakeTimers();
const e1 = interval(3).pipe(take(5));
const expected = [2, 3, 4];

Expand All @@ -379,9 +382,12 @@ describe('skipUntil', () => {
error: () => done(new Error('should not be called')),
complete: () => {
expect(expected.length).to.equal(0);
sandbox.restore();
done();
},
});

fakeTimers.tickAsync(15);
});

it('should raise error when Promise rejects', (done) => {
Expand Down
5 changes: 5 additions & 0 deletions packages/rxjs/spec/operators/window-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Observable} from 'rxjs';
import { EMPTY, of, interval } from 'rxjs';
import { observableMatcher } from '../helpers/observableMatcher';
import { expect } from 'chai';
import * as sinon from 'sinon';

/** @test {window} */
describe('window', () => {
Expand Down Expand Up @@ -284,6 +285,8 @@ describe('window', () => {
});

it('should window when Promise resolves', (done) => {
const sandbox = sinon.createSandbox();
const fakeTimers = sandbox.useFakeTimers();
const e1 = interval(3).pipe(take(5));
let pos = 0;
const result: number[][] = [[], []];
Expand All @@ -302,9 +305,11 @@ describe('window', () => {
error: () => done(new Error('should not be called')),
complete: () => {
expect(result).to.deep.equal(expected);
sandbox.restore();
done();
},
});
fakeTimers.tickAsync(15);
});

it('should raise error when Promise rejects', (done) => {
Expand Down
Loading