\`);
+
+ return function template(ctx, node, key = \\"\\") {
+ return block1();
+ }
+}"
+`;
diff --git a/tests/compiler/attributes.test.ts b/tests/compiler/attributes.test.ts
index 703fc556..658783de 100644
--- a/tests/compiler/attributes.test.ts
+++ b/tests/compiler/attributes.test.ts
@@ -315,62 +315,6 @@ describe("attributes", () => {
).toBe('
');
});
- test("changing an attribute with t-att-", () => {
- // render input with initial value
- const template = `
`;
- const bnode1 = renderToBdom(template, { v: "zucchini" });
- const fixture = makeTestFixture();
- mount(bnode1, fixture);
-
- expect(fixture.innerHTML).toBe('
');
-
- const bnode2 = renderToBdom(template, { v: "potato" });
- patch(bnode1, bnode2);
- expect(fixture.innerHTML).toBe('
');
-
- const bnode3 = renderToBdom(template, { v: "" });
- patch(bnode1, bnode3);
- // not sure about this. maybe we want to remove the attribute?
- expect(fixture.innerHTML).toBe('
');
- });
-
- test("dynamic input value: falsy values", () => {
- // 0 doesn't fall back to empty string
- expect(renderToBdom(`
`)).toEqual({ data: [new String("0")] });
- expect(renderToBdom(`
`)).toEqual({ data: [new String("")] });
- expect(renderToBdom(`
`)).toEqual({ data: [new String("")] });
- expect(renderToBdom(`
`)).toEqual({ data: [new String("")] });
- });
-
- test("updating property with falsy value", async () => {
- // render input with initial value
- const template = `
`;
- const bnode1 = renderToBdom(template, { v: false });
- const fixture = makeTestFixture();
- mount(bnode1, fixture);
-
- const input = fixture.querySelector("input")!;
- expect(input.value).toBe("");
-
- patch(bnode1, renderToBdom(template, { v: "owl" }));
- expect(input.value).toBe("owl");
-
- patch(bnode1, renderToBdom(template, { v: false }));
- expect(input.value).toBe("");
-
- patch(bnode1, renderToBdom(template, { v: "owl" }));
- expect(input.value).toBe("owl");
-
- patch(bnode1, renderToBdom(template, { v: undefined }));
- expect(input.value).toBe("");
-
- patch(bnode1, renderToBdom(template, { v: "owl" }));
- expect(input.value).toBe("owl");
-
- patch(bnode1, renderToBdom(template, { v: null }));
- expect(input.value).toBe("");
- });
-
test("changing a class with t-att-class", () => {
// render input with initial value
const template = `
`;
@@ -428,134 +372,3 @@ describe("attributes", () => {
expect(fixture.innerHTML).toBe('
');
});
});
-
-describe("special cases for some specific html attributes/properties", () => {
- test("input type= checkbox, with t-att-checked", () => {
- const template = `
`;
- const result = renderToString(template, { flag: true });
- expect(result).toBe(`
`);
- });
-
- test("various boolean html attributes", () => {
- // will cause the template to be snapshotted
- renderToString(`
-
- `);
- });
-
- test("input with t-att-value", () => {
- // render input with initial value
- const template = `
`;
- const bnode1 = renderToBdom(template, { v: "zucchini" });
- const fixture = makeTestFixture();
- mount(bnode1, fixture);
- const input = fixture.querySelector("input")!;
- expect(input.value).toBe("zucchini");
-
- // change value manually in input, to simulate user input
- input.value = "tomato";
- expect(input.value).toBe("tomato");
-
- // rerender with a different value, and patch actual dom, to check that
- // input value was properly reset by owl
- const bnode2 = renderToBdom(template, { v: "potato" });
- patch(bnode1, bnode2);
- expect(input.value).toBe("potato");
- });
-
- test("input with t-att-value (patching with same value", () => {
- // render input with initial value
- const template = `
`;
- const bnode1 = renderToBdom(template, { v: "zucchini" });
- const fixture = makeTestFixture();
- mount(bnode1, fixture);
- const input = fixture.querySelector("input")!;
- expect(input.value).toBe("zucchini");
-
- // change value manually in input, to simulate user input
- input.value = "tomato";
- expect(input.value).toBe("tomato");
-
- const bnode2 = renderToBdom(template, { v: "zucchini" });
- patch(bnode1, bnode2);
- expect(input.value).toBe("zucchini");
- });
-
- test("input, type checkbox, with t-att-checked (patching with same value", () => {
- // render input with initial value
- const template = `
`;
- const bnode1 = renderToBdom(template, { v: true });
- const fixture = makeTestFixture();
- mount(bnode1, fixture);
- const input = fixture.querySelector("input")!;
- expect(input.checked).toBe(true);
-
- // change checked manually in input, to simulate user input
- input.checked = false;
- expect(input.checked).toBe(false);
-
- const bnode2 = renderToBdom(template, { v: true });
- patch(bnode1, bnode2);
- expect(input.checked).toBe(true);
- });
-
- test("input of type checkbox with t-att-indeterminate", () => {
- const template = `
`;
- const bnode1 = renderToBdom(template, { v: true });
- const fixture = makeTestFixture();
- mount(bnode1, fixture);
- const input = fixture.querySelector("input")!;
- expect(input.indeterminate).toBe(true);
- });
-
- test("textarea with t-att-value", () => {
- // render textarea with initial value
- const template = `
`;
- const bnode1 = renderToBdom(template, { v: "zucchini" });
- const fixture = makeTestFixture();
- mount(bnode1, fixture);
- const elm = fixture.querySelector("textarea")!;
- expect(elm.value).toBe("zucchini");
-
- // change value manually in textarea, to simulate user textarea
- elm.value = "tomato";
- expect(elm.value).toBe("tomato");
-
- // rerender with a different value, and patch actual dom, to check that
- // textarea value was properly reset by owl
- const bnode2 = renderToBdom(template, { v: "potato" });
- patch(bnode1, bnode2);
- expect(elm.value).toBe("potato");
- });
-
- test("select with t-att-value", () => {
- const template = `
-
`;
- const bnode1 = renderToBdom(template, { value: "tomato" });
- const fixture = makeTestFixture();
- mount(bnode1, fixture);
- const elm = fixture.querySelector("select")!;
- expect(elm.value).toBe("tomato");
-
- elm.value = "potato";
- expect(elm.value).toBe("potato");
-
- // rerender with a different value, and patch actual dom, to check that
- // select value was properly reset by owl
- const bnode2 = renderToBdom(template, { value: "onion" });
- patch(bnode1, bnode2);
- expect(elm.value).toBe("onion");
- });
-});
diff --git a/tests/compiler/properties.test.ts b/tests/compiler/properties.test.ts
new file mode 100644
index 00000000..9eceee3d
--- /dev/null
+++ b/tests/compiler/properties.test.ts
@@ -0,0 +1,189 @@
+import { mount, patch } from "../../src/runtime/blockdom";
+import { makeTestFixture, renderToBdom, renderToString, snapshotEverything } from "../helpers";
+
+snapshotEverything();
+test("changing an attribute with t-att-", () => {
+ // render input with initial value
+ const template = `
`;
+ const bnode1 = renderToBdom(template, { v: "zucchini" });
+ const fixture = makeTestFixture();
+ mount(bnode1, fixture);
+
+ expect(fixture.innerHTML).toBe('
');
+
+ const bnode2 = renderToBdom(template, { v: "potato" });
+ patch(bnode1, bnode2);
+ expect(fixture.innerHTML).toBe('
');
+
+ const bnode3 = renderToBdom(template, { v: "" });
+ patch(bnode1, bnode3);
+ // not sure about this. maybe we want to remove the attribute?
+ expect(fixture.innerHTML).toBe('
');
+});
+
+test("dynamic input value: falsy values", () => {
+ // 0 doesn't fall back to empty string
+ expect(renderToBdom(`
`)).toEqual({ data: [new String("0")] });
+ expect(renderToBdom(`
`)).toEqual({ data: [new String("")] });
+ expect(renderToBdom(`
`)).toEqual({ data: [new String("")] });
+ expect(renderToBdom(`
`)).toEqual({ data: [new String("")] });
+});
+
+test("updating property with falsy value", async () => {
+ // render input with initial value
+ const template = `
`;
+ const bnode1 = renderToBdom(template, { v: false });
+ const fixture = makeTestFixture();
+ mount(bnode1, fixture);
+
+ const input = fixture.querySelector("input")!;
+ expect(input.value).toBe("");
+
+ patch(bnode1, renderToBdom(template, { v: "owl" }));
+ expect(input.value).toBe("owl");
+
+ patch(bnode1, renderToBdom(template, { v: false }));
+ expect(input.value).toBe("");
+
+ patch(bnode1, renderToBdom(template, { v: "owl" }));
+ expect(input.value).toBe("owl");
+
+ patch(bnode1, renderToBdom(template, { v: undefined }));
+ expect(input.value).toBe("");
+
+ patch(bnode1, renderToBdom(template, { v: "owl" }));
+ expect(input.value).toBe("owl");
+
+ patch(bnode1, renderToBdom(template, { v: null }));
+ expect(input.value).toBe("");
+});
+
+
+test("input type= checkbox, with t-att-checked", () => {
+ const template = `
`;
+ const result = renderToString(template, { flag: true });
+ expect(result).toBe(`
`);
+});
+
+test("various boolean html attributes", () => {
+ // will cause the template to be snapshotted
+ renderToString(`
+
+ `);
+});
+
+test("input with t-att-value", () => {
+ // render input with initial value
+ const template = `
`;
+ const bnode1 = renderToBdom(template, { v: "zucchini" });
+ const fixture = makeTestFixture();
+ mount(bnode1, fixture);
+ const input = fixture.querySelector("input")!;
+ expect(input.value).toBe("zucchini");
+
+ // change value manually in input, to simulate user input
+ input.value = "tomato";
+ expect(input.value).toBe("tomato");
+
+ // rerender with a different value, and patch actual dom, to check that
+ // input value was properly reset by owl
+ const bnode2 = renderToBdom(template, { v: "potato" });
+ patch(bnode1, bnode2);
+ expect(input.value).toBe("potato");
+});
+
+test("input with t-att-value (patching with same value", () => {
+ // render input with initial value
+ const template = `
`;
+ const bnode1 = renderToBdom(template, { v: "zucchini" });
+ const fixture = makeTestFixture();
+ mount(bnode1, fixture);
+ const input = fixture.querySelector("input")!;
+ expect(input.value).toBe("zucchini");
+
+ // change value manually in input, to simulate user input
+ input.value = "tomato";
+ expect(input.value).toBe("tomato");
+
+ const bnode2 = renderToBdom(template, { v: "zucchini" });
+ patch(bnode1, bnode2);
+ expect(input.value).toBe("zucchini");
+});
+
+test("input, type checkbox, with t-att-checked (patching with same value", () => {
+ // render input with initial value
+ const template = `
`;
+ const bnode1 = renderToBdom(template, { v: true });
+ const fixture = makeTestFixture();
+ mount(bnode1, fixture);
+ const input = fixture.querySelector("input")!;
+ expect(input.checked).toBe(true);
+
+ // change checked manually in input, to simulate user input
+ input.checked = false;
+ expect(input.checked).toBe(false);
+
+ const bnode2 = renderToBdom(template, { v: true });
+ patch(bnode1, bnode2);
+ expect(input.checked).toBe(true);
+});
+
+test("input of type checkbox with t-att-indeterminate", () => {
+ const template = `
`;
+ const bnode1 = renderToBdom(template, { v: true });
+ const fixture = makeTestFixture();
+ mount(bnode1, fixture);
+ const input = fixture.querySelector("input")!;
+ expect(input.indeterminate).toBe(true);
+});
+
+test("textarea with t-att-value", () => {
+ // render textarea with initial value
+ const template = `
`;
+ const bnode1 = renderToBdom(template, { v: "zucchini" });
+ const fixture = makeTestFixture();
+ mount(bnode1, fixture);
+ const elm = fixture.querySelector("textarea")!;
+ expect(elm.value).toBe("zucchini");
+
+ // change value manually in textarea, to simulate user textarea
+ elm.value = "tomato";
+ expect(elm.value).toBe("tomato");
+
+ // rerender with a different value, and patch actual dom, to check that
+ // textarea value was properly reset by owl
+ const bnode2 = renderToBdom(template, { v: "potato" });
+ patch(bnode1, bnode2);
+ expect(elm.value).toBe("potato");
+});
+
+test("select with t-att-value", () => {
+ const template = `
+
`;
+ const bnode1 = renderToBdom(template, { value: "tomato" });
+ const fixture = makeTestFixture();
+ mount(bnode1, fixture);
+ const elm = fixture.querySelector("select")!;
+ expect(elm.value).toBe("tomato");
+
+ elm.value = "potato";
+ expect(elm.value).toBe("potato");
+
+ // rerender with a different value, and patch actual dom, to check that
+ // select value was properly reset by owl
+ const bnode2 = renderToBdom(template, { value: "onion" });
+ patch(bnode1, bnode2);
+ expect(elm.value).toBe("onion");
+});