From 1f6e84d141500785233dbd803c5f87e095898e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Sat, 13 Nov 2021 17:10:06 +0100 Subject: [PATCH] [FIX] unskip tests --- .../__snapshots__/basics.test.ts.snap | 45 ++++++++++ .../__snapshots__/style_class.test.ts.snap | 2 +- .../__snapshots__/t_props.test.ts.snap | 59 +++++++++++++ tests/components/basics.test.ts | 83 +------------------ tests/components/style_class.test.ts | 10 ++- tests/components/t_props.test.ts | 54 ++++++++++++ 6 files changed, 167 insertions(+), 86 deletions(-) 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(\`
__
\`); + + return function template(ctx, node, key = \\"\\") { + let d1 = ctx['props'].key; + let d2 = ctx['props'].subKey; + return block1([d1, d2]); + } +}" +`; + +exports[`basics update props of component without concrete own node 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; + + return function template(ctx, node, key = \\"\\") { + const tKey_1 = ctx['props'].subKey; + return toggler(tKey_1, component(\`Custom\`, {key: ctx['props'].key,subKey: ctx['props'].subKey}, tKey_1 + key + \`__2\`, node, ctx)); + } +}" +`; + +exports[`basics update props of component without concrete own node 3`] = ` +"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 = \\"\\") { + const tKey_1 = ctx['childProps'].key; + let b2 = toggler(tKey_1, component(\`Child\`, ctx['childProps'], tKey_1 + key + \`__2\`, node, ctx)); + return block1([], [b2]); + } +}" +`; + exports[`basics updating a component with t-foreach as root 1`] = ` "function anonymous(bdom, helpers ) { diff --git a/tests/components/__snapshots__/style_class.test.ts.snap b/tests/components/__snapshots__/style_class.test.ts.snap index 1a638694..e330c391 100644 --- a/tests/components/__snapshots__/style_class.test.ts.snap +++ b/tests/components/__snapshots__/style_class.test.ts.snap @@ -141,7 +141,7 @@ exports[`style and class handling class on components do not interfere with user "function anonymous(bdom, helpers ) { let { text, createBlock, list, multi, html, toggler, component } = bdom; - let { withDefault, getTemplate, prepareList, withKey, zero, call, callSlot, capture, shallowEqual } = helpers; + 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); + }); });