smartrx/test/test.observablemap.ts

37 lines
1.2 KiB
TypeScript
Raw Normal View History

2017-10-26 20:56:01 +00:00
// import test framework
import { expect, tap } from 'tapbundle'
import * as events from 'events'
import * as rx from 'rxjs/Rx'
import * as smartq from 'smartq'
// import the module
import * as smartrx from '../ts/index'
let testObservablemap: smartrx.Observablemap
let testObservable1: rx.Observable<any>
let testObservable2: rx.Observable<any>
let testObservable3: rx.Observable<any>
let testEmitter: events.EventEmitter
tap.test('should create an instance', async () => {
testObservablemap = new smartrx.Observablemap()
expect(testObservablemap).be.instanceof(smartrx.Observablemap)
})
tap.test('should accept a new emitter', async () => {
let done = smartq.defer()
testEmitter = new events.EventEmitter()
testObservable1 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event1')
testObservable1.subscribe(x => {
done.resolve()
})
testObservable2 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event1')
testObservable3 = testObservablemap.getObservableForEmitterEvent(testEmitter, 'event2')
2017-11-01 13:59:28 +00:00
expect(testObservable1 === testObservable2).be.true()
expect(testObservable1 === testObservable3).be.false()
2017-10-26 20:56:01 +00:00
testEmitter.emit('event1')
await done.promise
})
tap.start()