Skip to content

Instantly share code, notes, and snippets.

@timnew
Last active March 15, 2016 11:39
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 timnew/d77c5a3c28ee7d766355 to your computer and use it in GitHub Desktop.
Save timnew/d77c5a3c28ee7d766355 to your computer and use it in GitHub Desktop.
RxJS Test Helper
class ObservableMonitor {
constructor(observable) {
this.observable = observable
this.promise = observable.materialize().toArray().toPromise()
}
complete(subject = this.observable) {
subject.onCompleted()
return this
}
async toNotifications() {
if (this.notifications == null) {
this.notifications = await this.promise
this.notifications.pop()
}
return this.notifications
}
async kinds() {
await this.toNotifications()
return this.notifications.map(notification => notification.kind)
}
async values() {
await this.toNotifications()
return this.notifications.map(notification => notification.value)
}
async errors() {
await this.toNotifications()
return this.notifications.map(notification => notification.error)
}
async pluckValues(key) {
await this.toNotifications()
return this.notifications.map(notification => notification.value && notification.value[key])
}
}
function monitorRx(observable) {
return new ObservableMonitor(observable)
}
global.monitorRx = monitorRx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment