Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

pipe.test.ts

44 lines928 Bytes

1import { describe, expect, test } from "vitest"
2import { D2 } from "../../src/d2.js"
3import { MultiSet } from "../../src/multiset.js"
4import { map, output, pipe } from "../../src/operators/index.js"
5​
6describe(`Operators`, () => {
7 describe(`Pipe operation`, () => {
8 test(`basic pipe operation`, () => {
9 const graph = new D2()
10 const input = graph.newInput<number>()
11 const messages: Array<MultiSet<number>> = []
12​
13 input.pipe(
14 pipe(
15 map((x) => x + 5),
16 map((x) => x * 2)
17 ),
18 output((message) => {
19 messages.push(message)
20 })
21 )
22​
23 graph.finalize()
24​
25 input.sendData(
26 new MultiSet([
27 [1, 1],
28 [2, 1],
29 [3, 1],
30 ])
31 )
32​
33 graph.run()
34​
35 expect(messages).toEqual([
36 new MultiSet([
37 [12, 1],
38 [14, 1],
39 [16, 1],
40 ]),
41 ])
42 })
43 })
44})