From 219102f952c5d52c5b166addd3f462dbae620417 Mon Sep 17 00:00:00 2001 From: Tushar Mathur Date: Sun, 25 Mar 2018 17:31:07 +0530 Subject: [PATCH] fix(testScheduler): fix normalizeEvents() utility noremalizeEvents() failed to parse events if only one was passed at a time --- src/schedulers/TestScheduler.ts | 1 + test/test.TestScheduler.ts | 55 ++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/schedulers/TestScheduler.ts b/src/schedulers/TestScheduler.ts index 56f349e..3730fed 100644 --- a/src/schedulers/TestScheduler.ts +++ b/src/schedulers/TestScheduler.ts @@ -39,6 +39,7 @@ function normalizeEvents(events: string): EventSource function normalizeEvents(events: any) { if (typeof events === 'string') return fromMarble(events) if (arguments.length > 1) return Array.from(arguments) + if (arguments.length === 1) return Array.isArray(events) ? events : [events] return events } diff --git a/test/test.TestScheduler.ts b/test/test.TestScheduler.ts index a71b07a..89bed92 100644 --- a/test/test.TestScheduler.ts +++ b/test/test.TestScheduler.ts @@ -6,36 +6,49 @@ import {EVENT} from '../src/internal/Events' import {createTestScheduler} from '../src/schedulers/TestScheduler' describe('new TestScheduler()', () => { - it('should just ... ', () => { - const sh = createTestScheduler() - assert.strictEqual(sh.now(), 0) + describe('now()', () => { + it('should return current time', () => { + const sh = createTestScheduler() - sh.advanceBy(10) - assert.strictEqual(sh.now(), 10) + assert.strictEqual(sh.now(), 0) - sh.advanceBy(2) - assert.strictEqual(sh.now(), 12) + sh.advanceBy(10) + assert.strictEqual(sh.now(), 10) - sh.advanceTo(20) - assert.strictEqual(sh.now(), 20) + sh.advanceBy(2) + assert.strictEqual(sh.now(), 12) + + sh.advanceTo(20) + assert.strictEqual(sh.now(), 20) + }) }) - it('should just ... ', () => { - const sh = createTestScheduler() - const {results} = sh.start(() => - sh.Hot([ + describe('start()', () => { + it('should return TestObserver', () => { + const sh = createTestScheduler() + const {results} = sh.start(() => + sh.Hot([ + EVENT.next(210, '0'), + EVENT.next(220, '1'), + EVENT.next(230, '2'), + EVENT.complete(240) + ]) + ) + + assert.deepEqual(results, [ EVENT.next(210, '0'), EVENT.next(220, '1'), EVENT.next(230, '2'), EVENT.complete(240) ]) - ) - - assert.deepEqual(results, [ - EVENT.next(210, '0'), - EVENT.next(220, '1'), - EVENT.next(230, '2'), - EVENT.complete(240) - ]) + }) + }) + + describe('Hot()', () => { + it('should create events ', () => { + const sh = createTestScheduler() + const {results} = sh.start(() => sh.Hot(EVENT.next(210, '0'))) + assert.deepEqual(results, [EVENT.next(210, '0')]) + }) }) })