mirror of
https://github.com/re-rxjs/react-rxjs.git
synced 2025-12-08 18:01:51 +00:00
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { TestScheduler } from "rxjs/testing"
|
|
import { switchMapSuspended, SUSPENSE } from "../../src"
|
|
|
|
const scheduler = () =>
|
|
new TestScheduler((actual, expected) => {
|
|
expect(actual).toEqual(expected)
|
|
})
|
|
|
|
describe("operators/switchMapSuspended", () => {
|
|
it("acts like a switchMap, but emitting a SUSPENSE when activating the inner stream", () => {
|
|
scheduler().run(({ expectObservable, cold }) => {
|
|
const source = cold("-x---")
|
|
const inner = cold(" ----a")
|
|
const expected = " -s---a"
|
|
|
|
const result$ = source.pipe(switchMapSuspended(() => inner))
|
|
|
|
expectObservable(result$).toBe(expected, {
|
|
s: SUSPENSE,
|
|
a: "a",
|
|
})
|
|
})
|
|
})
|
|
|
|
it("emits another SUSPENSE when another inner stream activates", () => {
|
|
scheduler().run(({ expectObservable, cold }) => {
|
|
const source = cold("-x--x")
|
|
const inner = cold(" ----a")
|
|
const expected = " -s--s---a"
|
|
|
|
const result$ = source.pipe(switchMapSuspended(() => inner))
|
|
|
|
expectObservable(result$).toBe(expected, {
|
|
s: SUSPENSE,
|
|
a: "a",
|
|
})
|
|
})
|
|
})
|
|
})
|