|
| 1 | +import * as assert from "uvu/assert"; |
| 2 | + |
| 3 | +import describe from "../util/describe.js"; |
| 4 | +import { createTree, waitForPath } from "../util/trees.js"; |
| 5 | +import { treeTeardown } from "../util/context.js"; |
| 6 | +import { diff } from "../util/snapshot.js"; |
| 7 | + |
| 8 | +import single from "./specimens/single.js"; |
| 9 | +import child from "./specimens/child.js"; |
| 10 | + |
| 11 | +describe("send", (it) => { |
| 12 | + it.after.each(treeTeardown); |
| 13 | + |
| 14 | + it("should be a callable method", async (context) => { |
| 15 | + const tree = context.tree = createTree(single); |
| 16 | + |
| 17 | + assert.type(tree.builder.send, "function"); |
| 18 | + }); |
| 19 | + |
| 20 | + it("should send to the root tree", async (context) => { |
| 21 | + const tree = context.tree = createTree(single); |
| 22 | + |
| 23 | + const { tree : one } = await tree(); |
| 24 | + |
| 25 | + tree.builder.send("NEXT"); |
| 26 | + |
| 27 | + const { tree : two } = await waitForPath(tree, "two"); |
| 28 | + |
| 29 | + diff(one, two, ` |
| 30 | + [ |
| 31 | + [Object: null prototype] { |
| 32 | + Actual: |
| 33 | + -- path: "one", |
| 34 | + -- component: [Function: one], |
| 35 | + Expected: |
| 36 | + ++ path: "two", |
| 37 | + ++ component: [Function: two], |
| 38 | + props: false, |
| 39 | + children: [] |
| 40 | + } |
| 41 | + ]`); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should *not* send to child trees", async (context) => { |
| 45 | + const tree = context.tree = createTree(child); |
| 46 | + |
| 47 | + const { tree : one } = await tree(); |
| 48 | + |
| 49 | + tree.builder.send("NEXT"); |
| 50 | + |
| 51 | + const { tree : two } = await waitForPath(tree, "root.two"); |
| 52 | + |
| 53 | + diff(one, two, ` |
| 54 | + [ |
| 55 | + [Object: null prototype] { |
| 56 | + Actual: |
| 57 | + -- path: "root.one", |
| 58 | + -- component: [Function: one], |
| 59 | + Expected: |
| 60 | + ++ path: "root.two", |
| 61 | + ++ component: [Function: two], |
| 62 | + props: false, |
| 63 | + children: [] |
| 64 | + }, |
| 65 | + [Object: null prototype] { |
| 66 | + path: "child.one", |
| 67 | + component: [Function: child-one], |
| 68 | + props: false, |
| 69 | + children: [] |
| 70 | + } |
| 71 | + ]`); |
| 72 | + }); |
| 73 | +}); |
0 commit comments