Skip to content

Commit badaa7e

Browse files
committed
Add tests for corner cases
1 parent 010680d commit badaa7e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/index.test.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ describe('htm', () => {
5252
test('single prop with static value', () => {
5353
expect(html`<a href="/hello" />`).toEqual({ tag: 'a', props: { href: '/hello' }, children: [] });
5454
});
55+
56+
test('single prop with static value followed by a single boolean prop', () => {
57+
expect(html`<a href="/hello" b />`).toEqual({ tag: 'a', props: { href: '/hello', b: true }, children: [] });
58+
});
5559

5660
test('two props with static values', () => {
5761
expect(html`<a href="/hello" target="_blank" />`).toEqual({ tag: 'a', props: { href: '/hello', target: '_blank' }, children: [] });
@@ -75,6 +79,9 @@ describe('htm', () => {
7579
expect(html`<a b ...${{ foo: 'bar' }} />`).toEqual({ tag: 'a', props: { b: true, foo: 'bar' }, children: [] });
7680
expect(html`<a b c ...${{ foo: 'bar' }} />`).toEqual({ tag: 'a', props: { b: true, c: true, foo: 'bar' }, children: [] });
7781
expect(html`<a ...${{ foo: 'bar' }} b />`).toEqual({ tag: 'a', props: { b: true, foo: 'bar' }, children: [] });
82+
expect(html`<a b="1" ...${{ foo: 'bar' }} />`).toEqual({ tag: 'a', props: { b: '1', foo: 'bar' }, children: [] });
83+
expect(html`<a x="1"><b y="2" ...${{ c: 'bar' }}/></a>`).toEqual(h('a', { x: '1' }, h('b', { y: '2', c: 'bar' }) ));
84+
expect(html`<a ...${{ c: 'bar' }}><b ...${{ d: 'baz' }}/></a>`).toEqual(h('a', { c: 'bar' }, h('b', { d: 'baz' }) ));
7885
});
7986

8087
test('mixed spread + static props', () => {
@@ -134,4 +141,23 @@ describe('htm', () => {
134141
</a>
135142
`).toEqual(h('a', null, 'before', 'foo', h('b', null), 'bar', 'after'));
136143
});
144+
145+
test('hyphens (-) are allowed in attribute names', () => {
146+
expect(html`<a b-c></a>`).toEqual(h('a', { 'b-c': true }));
147+
});
148+
149+
test('NUL characters are allowed in attribute values', () => {
150+
expect(html`<a b="\0"></a>`).toEqual(h('a', { b: '\0' }));
151+
expect(html`<a b="\0" c=${'foo'}></a>`).toEqual(h('a', { b: '\0', c: 'foo' }));
152+
});
153+
154+
test('NUL characters are allowed in text', () => {
155+
expect(html`<a>\0</a>`).toEqual(h('a', null, '\0'));
156+
expect(html`<a>\0${'foo'}</a>`).toEqual(h('a', null, '\0', 'foo'));
157+
});
158+
159+
test('cache key should be unique', () => {
160+
html`<a b="${'foo'}" />`;
161+
expect(html`<a b="\0" />`).toEqual(h('a', { b: '\0' }));
162+
});
137163
});

0 commit comments

Comments
 (0)