release: WRNexusJS 0.2.46
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { test, expect, beforeEach } from "bun:test";
|
||||
import { Window } from "happy-dom";
|
||||
import { REACTIVE_RUNTIME } from "../src/reactive-runtime.ts";
|
||||
import { mountHtml } from "@wrnexus/test";
|
||||
|
||||
// Fresh DOM per test, with the runtime's globals bound.
|
||||
function mount(html: string): Window {
|
||||
@@ -164,3 +165,48 @@ test("independent signals in one scope update correctly (dependency tracking)",
|
||||
click("bb");
|
||||
expect([ta(), tb()]).toEqual(["2", "101"]);
|
||||
});
|
||||
test("data-for preserves arrays of objects from encoded component scope", () => {
|
||||
const items = [
|
||||
{
|
||||
question: "One",
|
||||
answer: "First",
|
||||
},
|
||||
{
|
||||
question: "Two",
|
||||
answer: "Second",
|
||||
},
|
||||
{
|
||||
question: "Three",
|
||||
answer: "Third",
|
||||
},
|
||||
{
|
||||
question: "Four",
|
||||
answer: "Fourth",
|
||||
},
|
||||
];
|
||||
|
||||
const encoded = Buffer.from(
|
||||
JSON.stringify({
|
||||
items,
|
||||
}),
|
||||
"utf8",
|
||||
).toString("base64");
|
||||
|
||||
const dom = mountHtml(`
|
||||
<div data-wrn-scope="${encoded}">
|
||||
<article data-for="item, index in items">
|
||||
<span>{index + 1}</span>
|
||||
<strong>{item.question}</strong>
|
||||
</article>
|
||||
</div>
|
||||
`);
|
||||
|
||||
expect(dom.querySelectorAll("article")).toHaveLength(4);
|
||||
|
||||
expect(dom.querySelectorAll("strong").map((element) => element.textContent)).toEqual([
|
||||
"One",
|
||||
"Two",
|
||||
"Three",
|
||||
"Four",
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user