Skip to content

Instantly share code, notes, and snippets.

@valotas
Last active March 19, 2016 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valotas/09f8fabc1a1db4b108b3 to your computer and use it in GitHub Desktop.
Save valotas/09f8fabc1a1db4b108b3 to your computer and use it in GitHub Desktop.
/*eslint-env jasmine*/
import Rx from 'rxjs';
fdescribe('TestScheduler', () => {
describe('createHotObservable()', () => {
it('should create a hot observable emmiting the values given as marble strings', () => {
//given
const scheduler = new Rx.TestScheduler(null);
const source = scheduler.createHotObservable('--a---b-cd-|');
const expected = ['ab', 'cd'];
//when
source
.bufferCount(2)
.map((array) => array.join(''))
.subscribe((val) => {
expect(val).toEqual(expected.shift());
});
scheduler.flush();
expect(expected.length).toBe(0);
});
});
describe('createColdObservable()', () => {
it('should create a cold observable emmiting the values given as marble strings', () => {
//given
const scheduler = new Rx.TestScheduler(null);
const source = scheduler.createColdObservable('--a---b|');
const expected = ['a', 'b'];
//when
source
.subscribe((val) => {
expect(val).toEqual(expected.shift());
});
scheduler.flush();
expect(expected.length).toBe(0);
});
});
});
/*eslint-env jasmine*/
import Rx from 'rxjs';
function assertEquals (actual, expected) {
//we will use jasmine's api for the assertion:
expect(actual).toEqual(expected);
}
describe('TestScheduler', () => {
describe('expectObservable()', () => {
it('should simplify the result check of given observables', () => {
//given
const scheduler = new Rx.TestScheduler(assertEquals);
const source = scheduler.createHotObservable('--a-^--b-c');
//then
scheduler.expectObservable(source).toBe('---bc');
scheduler.flush();
});
});
});
/*eslint-env jasmine*/
import Rx from 'rxjs';
describe('TestScheduler', () => {
describe('schedule()', () => {
it('should schedule the subscription on the right time', () => {
//given
const scheduler = new Rx.TestScheduler(null);
const source = scheduler.createHotObservable('--a-^--b-c|');
const results = [];
//when
scheduler.schedule(() => {
source.subscribe((val) => {
results.push(val);
}, null, () => {
results.push('done');
});
});
scheduler.flush();
expect(results).toEqual(['b', 'c', 'done']);
});
it('should allow scheduling of non ending streams', () => {
//given
const scheduler = new Rx.TestScheduler(null);
const source = scheduler.createHotObservable('--a-^--b-c');
const results = [];
//when
scheduler.schedule(() => {
source.subscribe((val) => {
results.push(val);
}, null, () => {
results.push('done');
});
});
scheduler.flush();
expect(results).toEqual(['b', 'c']);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment