Skip to content

Commit

Permalink
fix(cache): throw when update internal properties of the target (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban authored Sep 20, 2024
1 parent 9ccd06c commit 52f5053
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ export function get(target, key, fn) {
}

export function assert(target, key, value, force) {
if (context && !force) {
if (context && context.target === target && !force) {
throw Error(
`Try to assert value of the '${key}' inside of the value function`,
`Try to update the '${key}' property while getting the '${context.key}' property`,
);
}

Expand Down
30 changes: 30 additions & 0 deletions test/spec/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,36 @@ describe("html:", () => {
});
});

it("sets the property value of the nested element", () => {
define({
tag: "test-html-assert-nested",
value: "",
});

define({
tag: "test-html-assert",
value: "test",
target: ({ render }) => render().querySelector("div"),
render: ({ value }) =>
html`<test-html-assert-nested
value="${value}"
></test-html-assert-nested>`,
});

const render = html`<test-html-assert></test-html-assert>`;

render(fragment);

const el = fragment.children[0];

return resolveTimeout(() => {
expect(() => {
el.value = "other";
el.target;
}).not.toThrow();
});
});

describe("attribute expression with combined text value", () => {
const render = (two, three) => html`
<div name="test" class="class-one ${two} ${three}"></div>
Expand Down

0 comments on commit 52f5053

Please sign in to comment.