Skip to content

Commit c1a04f3

Browse files
committed
Add a test for forcing subtree staticness
1 parent 81d998d commit c1a04f3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/statics-caching.test.mjs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,25 @@ describe('htm', () => {
8989
expect(html`<div x=${1}><a y=${2} /><b /></div>`).toBe(3);
9090
});
9191
});
92+
93+
describe('the h function should be able to modify `this[0]`', () => {
94+
test('should be able to force subtrees to be static', () => {
95+
function wrapH(h) {
96+
return function(type, props, ...children) {
97+
if (props['@static']) {
98+
this[0] &= ~3;
99+
}
100+
return h(type, props, ...children);
101+
};
102+
}
103+
104+
const html = htm.bind(wrapH(h));
105+
const x = () => html`<div @static>${'a'}</div>`;
106+
const a = x();
107+
const b = x();
108+
expect(a).toEqual({ tag: 'div', props: { '@static': true }, children: ['a'] });
109+
expect(b).toEqual({ tag: 'div', props: { '@static': true }, children: ['a'] });
110+
expect(a).toBe(b);
111+
});
112+
});
92113
});

0 commit comments

Comments
 (0)