Skip to content

Commit 9bfed78

Browse files
committed
Add a test ensuring that each h has a separate subtree cache
1 parent bdbee85 commit 9bfed78

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

test/statics-caching.test.mjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,23 @@ const h = (tag, props, ...children) => ({ tag, props, children });
1717
const html = htm.bind(h);
1818

1919
describe('htm', () => {
20-
test('caching', () => {
20+
test('should cache static subtrees', () => {
2121
const x = () => html`<div>a</div>`;
2222
const a = x();
2323
const b = x();
2424
expect(a).toEqual({ tag: 'div', props: null, children: ['a'] });
2525
expect(b).toEqual({ tag: 'div', props: null, children: ['a'] });
2626
expect(a).toBe(b);
2727
});
28+
29+
test('should have a different cache for each h', () => {
30+
let tmp = htm.bind(() => 1);
31+
const x = () => tmp`<div>a</div>`;
32+
const a = x();
33+
tmp = htm.bind(() => 2);
34+
const b = x();
35+
36+
expect(a).toBe(1);
37+
expect(b).toBe(2);
38+
});
2839
});

0 commit comments

Comments
 (0)