Skip to content

Commit

Permalink
Merge branch 'master' into fix-typings
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister authored Jan 24, 2020
2 parents b9b7c98 + c82c4eb commit 1c077dd
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/statics-caching.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,39 @@ describe('htm', () => {
expect(html`<div x=${1}><a y=${2} /><b /></div>`).toBe(3);
});
});

describe('the h function should be able to modify `this[0]`', () => {
function wrapH(h) {
return function(type, props, ...children) {
if (type === '@static') {
this[0] &= ~3;
return children;
}
if (props['@static']) {
this[0] &= ~3;
}
return h(type, props, ...children);
};
}

test('should be able to force subtrees to be static via a prop', () => {
const html = htm.bind(wrapH(h));
const x = () => html`<div @static>${'a'}</div>`;
const a = x();
const b = x();
expect(a).toEqual({ tag: 'div', props: { '@static': true }, children: ['a'] });
expect(b).toEqual({ tag: 'div', props: { '@static': true }, children: ['a'] });
expect(a).toBe(b);
});

test('should be able to force subtrees to be static via a special tag', () => {
const html = htm.bind(wrapH(h));
const x = () => html`<@static>${'a'}<//>`;
const a = x();
const b = x();
expect(a).toEqual(['a']);
expect(b).toEqual(['a']);
expect(a).toBe(b);
});
});
});

0 comments on commit 1c077dd

Please sign in to comment.