test(shareLatest): recursive sync subscriptions

This commit is contained in:
Josep M Sobrepere Profitós 2020-08-06 23:55:41 +02:00 committed by Josep M Sobrepere
parent ca5d2ea5e6
commit 5e9be40398

View File

@ -1,6 +1,7 @@
import { TestScheduler } from "rxjs/testing"
import { from } from "rxjs"
import { from, merge, defer } from "rxjs"
import { shareLatest } from "../"
import { withLatestFrom, startWith, map } from "rxjs/operators"
const scheduler = () =>
new TestScheduler((actual, expected) => {
@ -49,6 +50,29 @@ describe("shareLatest", () => {
})
})
// prettier-ignore
it("should be able to handle recursively synchronous subscriptions", () => {
scheduler().run(({ expectObservable, hot }) => {
const values$ = hot('----b-c-d---')
const latest$ = hot('----------x-')
const expected = ' a---b-c-d-d-'
const input$ = merge(
values$,
latest$.pipe(
withLatestFrom(defer(() => result$)),
map(([, latest]) => latest)
)
)
const result$ = input$.pipe(
startWith('a'),
shareLatest()
)
expectObservable(result$, '^').toBe(expected)
})
})
// prettier-ignore
it("should not skip values on a sync source", () => {
scheduler().run(({ expectObservable }) => {