Skip to content

Commit 55ed166

Browse files
committed
Add a test for forcing the subtree to be static via a special flag
1 parent c1a04f3 commit 55ed166

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

test/statics-caching.test.mjs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,20 @@ describe('htm', () => {
9191
});
9292

9393
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-
94+
function wrapH(h) {
95+
return function(type, props, ...children) {
96+
if (type === '@static') {
97+
this[0] &= ~3;
98+
return children;
99+
}
100+
if (props['@static']) {
101+
this[0] &= ~3;
102+
}
103+
return h(type, props, ...children);
104+
};
105+
}
106+
107+
test('should be able to force subtrees to be static via a prop', () => {
104108
const html = htm.bind(wrapH(h));
105109
const x = () => html`<div @static>${'a'}</div>`;
106110
const a = x();
@@ -109,5 +113,15 @@ describe('htm', () => {
109113
expect(b).toEqual({ tag: 'div', props: { '@static': true }, children: ['a'] });
110114
expect(a).toBe(b);
111115
});
116+
117+
test('should be able to force subtrees to be static via a special tag', () => {
118+
const html = htm.bind(wrapH(h));
119+
const x = () => html`<@static>${'a'}<//>`;
120+
const a = x();
121+
const b = x();
122+
expect(a).toEqual(['a']);
123+
expect(b).toEqual(['a']);
124+
expect(a).toBe(b);
125+
});
112126
});
113127
});

0 commit comments

Comments
 (0)