Last active
March 15, 2016 11:39
-
-
Save timnew/d77c5a3c28ee7d766355 to your computer and use it in GitHub Desktop.
RxJS Test Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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