Skip to content

Commit b4204d2

Browse files
author
Gray Norton
committed
Add tests for multiple spreads, case-sensitive props
1 parent e5daa21 commit b4204d2

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

test/preact.test.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ describe('preact-html', () => {
3636
`;
3737
}
3838
}
39-
4039
const Bar = ({ hello, children }) => html`
4140
<div>
4241
Value of hello: ${hello + ''}
4342
${children}
4443
</div>
4544
`;
4645

46+
const Baz = ({ myCaseSensitiveProp }) => html`<div>${myCaseSensitiveProp}</div>`;
47+
4748
const fullHtml = '<div class="foo">\n\t\t\t\t\t<h1>Name: jason</h1>\n\t\t\t\t\t<p>Hello world!</p>\n\t\t\t\t\t<button>Click Me</button>\n\t\t\t\t\t<pre>Count: 0</pre>\n\t\t\t\t\txml-style end tags:\n\t\t\t\t\t<div>\n\t\tValue of hello: true\n\t\t\n\t</div>\n\t\t\t\t\texplicit end tags:\n\t\t\t\t\t<div>\n\t\tValue of hello: true\n\t\tsome children (count=0)\n\t</div>\n\t\t\t\t\timplicit end tags: (&lt;//&gt;)\n\t\t\t\t\t<div>\n\t\tValue of hello: true\n\t\tsome children (count=0)\n\t</div>\n\t\t\t\t\tsome text at the end\n\t\t\t\t</div>';
4849

4950
test('initial render', () => {
@@ -65,10 +66,18 @@ describe('preact-html', () => {
6566
});
6667
});
6768

68-
test('spread props', () => {
69+
test('preserves case', () => {
70+
scratch.textContent = '';
71+
render(html`<${Baz} myCaseSensitiveProp="Yay!" />`, scratch);
72+
expect(scratch.innerHTML).toBe('<div>Yay!</div>');
73+
});
74+
75+
test('object spreads', () => {
6976
scratch.textContent = '';
7077

7178
const props = { a: 1, b: 2, c: 3 };
79+
const other = { d: 4, e: 5, f: 6 };
80+
7281
render(html`<div ...${props} />`, scratch);
7382
expect(scratch.innerHTML).toBe(`<div a="1" b="2" c="3"></div>`);
7483
scratch.innerHTML = '';
@@ -79,10 +88,17 @@ describe('preact-html', () => {
7988

8089
render(html`<div ...${props} is-after />`, scratch);
8190
expect(scratch.innerHTML).toBe(`<div a="1" b="2" c="3" is-after="true"></div>`);
91+
expect(JSON.stringify(props)).toBe(`{"a":1,"b":2,"c":3}`);
8292
scratch.innerHTML = '';
8393

8494
render(html`<div is-before ...${props} is-after="blah" />`, scratch);
8595
expect(scratch.innerHTML).toBe(`<div is-before="true" a="1" b="2" c="3" is-after="blah"></div>`);
96+
scratch.innerHTML = '';
97+
98+
render(html`<div ...${props} ...${other} />`, scratch);
99+
expect(scratch.innerHTML).toBe(`<div a="1" b="2" c="3" d="4" e="5" f="6"></div>`);
100+
scratch.innerHTML = '';
101+
86102
});
87103
});
88104

0 commit comments

Comments
 (0)