mirror of
https://github.com/re-rxjs/react-rxjs.git
synced 2025-12-08 18:01:51 +00:00
test(mergeWithKey): add tests to mergeWithKey
This commit is contained in:
parent
13a3de4ae7
commit
367128f238
34
packages/utils/src/mergeWithKey.spec.ts
Normal file
34
packages/utils/src/mergeWithKey.spec.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { map } from "rxjs/operators"
|
||||
import { TestScheduler } from "rxjs/testing"
|
||||
import { mergeWithKey } from "./mergeWithKey"
|
||||
|
||||
const scheduler = () =>
|
||||
new TestScheduler((actual, expected) => {
|
||||
expect(actual).toEqual(expected)
|
||||
})
|
||||
|
||||
describe("mergeWithKey", () => {
|
||||
it("emits the key of the stream that emitted the value", () => {
|
||||
scheduler().run(({ expectObservable, cold }) => {
|
||||
const sourceA = cold("a---b---|");
|
||||
const sourceB = cold("-1--2----3|")
|
||||
const expected = " mn--(op)-q|"
|
||||
|
||||
const result = mergeWithKey({
|
||||
strings: sourceA,
|
||||
numbers: sourceB
|
||||
}).pipe(
|
||||
map(({ type, payload }) => `${type}:${payload}`),
|
||||
)
|
||||
|
||||
expectObservable(result).toBe(expected, {
|
||||
m: "strings:a",
|
||||
n: "numbers:1",
|
||||
o: "strings:b",
|
||||
p: "numbers:2",
|
||||
q: "numbers:3",
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -1,6 +1,12 @@
|
||||
import { merge, Observable, ObservableInput, from, SchedulerLike } from "rxjs"
|
||||
import { map } from "rxjs/operators"
|
||||
|
||||
/**
|
||||
* Emits the values from all the streams of the provided object, in a result
|
||||
* which provides the key of the stream of that emission.
|
||||
*
|
||||
* @param input object of streams
|
||||
*/
|
||||
export const mergeWithKey: <
|
||||
O extends { [P in keyof any]: ObservableInput<any> },
|
||||
OT extends {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user