Skip to content

Commit 5e9be40

Browse files
committed
test(shareLatest): recursive sync subscriptions
1 parent ca5d2ea commit 5e9be40

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

packages/core/src/operators/share-latest.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { TestScheduler } from "rxjs/testing"
2-
import { from } from "rxjs"
2+
import { from, merge, defer } from "rxjs"
33
import { shareLatest } from "../"
4+
import { withLatestFrom, startWith, map } from "rxjs/operators"
45

56
const scheduler = () =>
67
new TestScheduler((actual, expected) => {
@@ -49,6 +50,29 @@ describe("shareLatest", () => {
4950
})
5051
})
5152

53+
// prettier-ignore
54+
it("should be able to handle recursively synchronous subscriptions", () => {
55+
scheduler().run(({ expectObservable, hot }) => {
56+
const values$ = hot('----b-c-d---')
57+
const latest$ = hot('----------x-')
58+
const expected = ' a---b-c-d-d-'
59+
const input$ = merge(
60+
values$,
61+
latest$.pipe(
62+
withLatestFrom(defer(() => result$)),
63+
map(([, latest]) => latest)
64+
)
65+
)
66+
67+
const result$ = input$.pipe(
68+
startWith('a'),
69+
shareLatest()
70+
)
71+
72+
expectObservable(result$, '^').toBe(expected)
73+
})
74+
})
75+
5276
// prettier-ignore
5377
it("should not skip values on a sync source", () => {
5478
scheduler().run(({ expectObservable }) => {

0 commit comments

Comments
 (0)