Skip to content

Commit

Permalink
fix(testScheduler): fix normalizeEvents() utility
Browse files Browse the repository at this point in the history
noremalizeEvents() failed to parse events if only one was passed at a time
  • Loading branch information
tusharmath committed Mar 25, 2018
1 parent e7b51ef commit 219102f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/schedulers/TestScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
55 changes: 34 additions & 21 deletions test/test.TestScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')])
})
})
})

0 comments on commit 219102f

Please sign in to comment.