Skip to content

Commit 219102f

Browse files
committed
fix(testScheduler): fix normalizeEvents() utility
noremalizeEvents() failed to parse events if only one was passed at a time
1 parent e7b51ef commit 219102f

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

src/schedulers/TestScheduler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function normalizeEvents(events: string): EventSource
3939
function normalizeEvents(events: any) {
4040
if (typeof events === 'string') return fromMarble(events)
4141
if (arguments.length > 1) return Array.from(arguments)
42+
if (arguments.length === 1) return Array.isArray(events) ? events : [events]
4243
return events
4344
}
4445

test/test.TestScheduler.ts

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,49 @@ import {EVENT} from '../src/internal/Events'
66
import {createTestScheduler} from '../src/schedulers/TestScheduler'
77

88
describe('new TestScheduler()', () => {
9-
it('should just ... ', () => {
10-
const sh = createTestScheduler()
11-
assert.strictEqual(sh.now(), 0)
9+
describe('now()', () => {
10+
it('should return current time', () => {
11+
const sh = createTestScheduler()
1212

13-
sh.advanceBy(10)
14-
assert.strictEqual(sh.now(), 10)
13+
assert.strictEqual(sh.now(), 0)
1514

16-
sh.advanceBy(2)
17-
assert.strictEqual(sh.now(), 12)
15+
sh.advanceBy(10)
16+
assert.strictEqual(sh.now(), 10)
1817

19-
sh.advanceTo(20)
20-
assert.strictEqual(sh.now(), 20)
18+
sh.advanceBy(2)
19+
assert.strictEqual(sh.now(), 12)
20+
21+
sh.advanceTo(20)
22+
assert.strictEqual(sh.now(), 20)
23+
})
2124
})
2225

23-
it('should just ... ', () => {
24-
const sh = createTestScheduler()
25-
const {results} = sh.start(() =>
26-
sh.Hot([
26+
describe('start()', () => {
27+
it('should return TestObserver', () => {
28+
const sh = createTestScheduler()
29+
const {results} = sh.start(() =>
30+
sh.Hot([
31+
EVENT.next(210, '0'),
32+
EVENT.next(220, '1'),
33+
EVENT.next(230, '2'),
34+
EVENT.complete(240)
35+
])
36+
)
37+
38+
assert.deepEqual(results, [
2739
EVENT.next(210, '0'),
2840
EVENT.next(220, '1'),
2941
EVENT.next(230, '2'),
3042
EVENT.complete(240)
3143
])
32-
)
33-
34-
assert.deepEqual(results, [
35-
EVENT.next(210, '0'),
36-
EVENT.next(220, '1'),
37-
EVENT.next(230, '2'),
38-
EVENT.complete(240)
39-
])
44+
})
45+
})
46+
47+
describe('Hot()', () => {
48+
it('should create events ', () => {
49+
const sh = createTestScheduler()
50+
const {results} = sh.start(() => sh.Hot(EVENT.next(210, '0')))
51+
assert.deepEqual(results, [EVENT.next(210, '0')])
52+
})
4053
})
4154
})

0 commit comments

Comments
 (0)