diff --git a/tests/components/__snapshots__/basics.test.ts.snap b/tests/components/__snapshots__/basics.test.ts.snap
index be9545ed..a408d83f 100644
--- a/tests/components/__snapshots__/basics.test.ts.snap
+++ b/tests/components/__snapshots__/basics.test.ts.snap
@@ -1019,6 +1019,51 @@ exports[`basics two child components 2`] = `
}"
`;
+exports[`basics update props of component without concrete own node 1`] = `
+"function anonymous(bdom, helpers
+) {
+ let { text, createBlock, list, multi, html, toggler, component } = bdom;
+ let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber } = helpers;
+
+ let block1 = createBlock(\`
\`);
diff --git a/tests/components/__snapshots__/t_props.test.ts.snap b/tests/components/__snapshots__/t_props.test.ts.snap
index 81507e34..af238e6d 100644
--- a/tests/components/__snapshots__/t_props.test.ts.snap
+++ b/tests/components/__snapshots__/t_props.test.ts.snap
@@ -1,5 +1,35 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`t-props basic use 1`] = `
+"function anonymous(bdom, helpers
+) {
+ let { text, createBlock, list, multi, html, toggler, component } = bdom;
+ let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber } = helpers;
+
+ let block1 = createBlock(\`
\`);
+
+ return function template(ctx, node, key = \\"\\") {
+ let d1 = ctx['props'].a+ctx['props'].b;
+ return block1([d1]);
+ }
+}"
+`;
+
+exports[`t-props basic use 2`] = `
+"function anonymous(bdom, helpers
+) {
+ let { text, createBlock, list, multi, html, toggler, component } = bdom;
+ let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber } = helpers;
+
+ let block1 = createBlock(\`
\`);
+
+ return function template(ctx, node, key = \\"\\") {
+ let b2 = component(\`Child\`, ctx['some'].obj, key + \`__1\`, node, ctx);
+ return block1([], [b2]);
+ }
+}"
+`;
+
exports[`t-props t-props and other props 1`] = `
"function anonymous(bdom, helpers
) {
@@ -60,3 +90,32 @@ exports[`t-props t-props only 2`] = `
}
}"
`;
+
+exports[`t-props t-props with props 1`] = `
+"function anonymous(bdom, helpers
+) {
+ let { text, createBlock, list, multi, html, toggler, component } = bdom;
+ let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber } = helpers;
+
+ let block1 = createBlock(\`
\`);
+
+ return function template(ctx, node, key = \\"\\") {
+ return block1();
+ }
+}"
+`;
+
+exports[`t-props t-props with props 2`] = `
+"function anonymous(bdom, helpers
+) {
+ let { text, createBlock, list, multi, html, toggler, component } = bdom;
+ let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, isBoundary, shallowEqual, setContextValue, toNumber } = helpers;
+
+ let block1 = createBlock(\`
\`);
+
+ return function template(ctx, node, key = \\"\\") {
+ let b2 = component(\`Child\`, Object.assign({}, ctx['props'], {a: 1,b: 2}), key + \`__1\`, node, ctx);
+ return block1([], [b2]);
+ }
+}"
+`;
diff --git a/tests/components/basics.test.ts b/tests/components/basics.test.ts
index 9620a3e6..43bbc810 100644
--- a/tests/components/basics.test.ts
+++ b/tests/components/basics.test.ts
@@ -772,8 +772,9 @@ describe("basics", () => {
await mount(Parent, fixture);
expect(fixture.innerHTML).toBe("
42");
});
+
// Depends on t-props
- test.skip("update props of component without concrete own node", async () => {
+ test("update props of component without concrete own node", async () => {
class Custom extends Component {
static template = xml`
@@ -820,86 +821,6 @@ describe("basics", () => {
await nextTick();
expect(fixture.textContent!.trim()).toBe("2__3");
});
-
- test.skip("subcomponents cannot change observable state received from parent", async () => {
- const consoleError = console.error;
- console.error = jest.fn();
- class Child extends Component {
- static template = xml`
`;
- setup() {
- this.props.obj.coffee = 2;
- }
- }
- class Parent extends Component {
- static template = xml`
`;
- static components = { Child };
- state = useState({ obj: { coffee: 1 } });
- }
- let error;
- try {
- await mount(Parent, fixture);
- } catch (e) {
- error = e;
- }
- expect(error).toBeDefined();
- expect(error.message).toBe('Observed state cannot be changed here! (key: "coffee", val: "2")');
- expect(console.error).toBeCalledTimes(0);
- console.error = consoleError;
- });
-});
-
-describe("dynamic t-props", () => {
- test.skip("basic use", async () => {
- expect.assertions(4);
-
- class Child extends Component {
- static template = xml`
-
-
-
- `;
- setup() {
- expect(this.props).toEqual({ a: 1, b: 2 });
- expect(this.props).not.toBe(parent.some.obj);
- }
- }
- class Parent extends Component {
- static template = xml`
-
-
-
- `;
- static components = { Child };
-
- some = { obj: { a: 1, b: 2 } };
- }
-
- const parent = await mount(Parent, fixture);
- expect(fixture.innerHTML).toBe("
3
");
- });
-
- test.skip("t-props with props", async () => {
- expect.assertions(1);
-
- class Child extends Component {
- static template = xml`
`;
- setup() {
- expect(this.props).toEqual({ a: 1, b: 2, c: "c" });
- }
- }
- class Parent extends Component {
- static template = xml`
-
-
-
- `;
- static components = { Child };
-
- props = { a: "a", c: "c" };
- }
-
- await mount(Parent, fixture);
- });
});
describe("mount targets", () => {
diff --git a/tests/components/style_class.test.ts b/tests/components/style_class.test.ts
index 378fc599..a6e61a04 100644
--- a/tests/components/style_class.test.ts
+++ b/tests/components/style_class.test.ts
@@ -1,4 +1,4 @@
-import { Component, mount, useState, xml } from "../../src";
+import { Component, mount, onMounted, useState, xml } from "../../src";
import { makeTestFixture, nextTick, snapshotEverything } from "../helpers";
snapshotEverything();
@@ -273,12 +273,14 @@ describe("style and class handling", () => {
expect(span.className).toBe("c a b d");
});
- test.skip("class on components do not interfere with user defined classes", async () => {
+ test("class on components do not interfere with user defined classes", async () => {
class App extends Component {
static template = xml`
`;
state = useState({ c: true });
- mounted() {
- (
this.el!).classList.add("user");
+ setup() {
+ onMounted(() => {
+ (this.el!).classList.add("user");
+ });
}
}
const widget = await mount(App, fixture);
diff --git a/tests/components/t_props.test.ts b/tests/components/t_props.test.ts
index f8d8d47a..3de1acd9 100644
--- a/tests/components/t_props.test.ts
+++ b/tests/components/t_props.test.ts
@@ -51,4 +51,58 @@ describe("t-props", () => {
await nextTick();
expect(fixture.textContent).toBe("second");
});
+
+ test("basic use", async () => {
+ expect.assertions(5);
+
+ let props = { a: 1, b: 2 };
+
+ class Child extends Component {
+ static template = xml`
+
+
+
+ `;
+ setup() {
+ expect(this.props).toEqual({ a: 1, b: 2 });
+ expect(this.props).toBe(props);
+ }
+ }
+ class Parent extends Component {
+ static template = xml`
+
+
+
+ `;
+ static components = { Child };
+
+ some = { obj: props };
+ }
+
+ await mount(Parent, fixture);
+ expect(fixture.innerHTML).toBe("3
");
+ });
+
+ test("t-props with props", async () => {
+ expect.assertions(3); // 2 comes from snapshots
+
+ class Child extends Component {
+ static template = xml``;
+ setup() {
+ expect(this.props).toEqual({ a: 1, b: 2, c: "c" });
+ }
+ }
+ class Parent extends Component {
+ static template = xml`
+
+
+
+ `;
+ static components = { Child };
+
+ props = { a: "a", c: "c" };
+ }
+
+ await mount(Parent, fixture);
+ });
});