Skip to content

Commit

Permalink
test: 100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Mar 1, 2024
1 parent bba98e2 commit d38983e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/html/test/async.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Async components', () => {
assert(await (<Async>{1}</Async>), '<div>1</div>');
});

test('Children', async () => {
test('Child', async () => {
const html = (
<Sync>
<Async>{1}</Async>
Expand All @@ -29,4 +29,20 @@ describe('Async components', () => {
assert.ok(html instanceof Promise);
assert(await html, '<div>1</div>');
});

test('Children', async () => {
const html = (
<div>
<Async>
{1} {2}
</Async>
<Async>
{3} {4}
</Async>
</div>
);

assert.ok(html instanceof Promise);
assert(await html, '<div>1234</div>');
});
});
34 changes: 34 additions & 0 deletions packages/html/test/runtime.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import { jsx, jsxs } from '../jsx-runtime';

describe('Runtime behavior of JSX', () => {
test('createElement', () => {
function Component(props: any) {
return <div {...props}></div>;
}

async function AsyncComponent() {
return Promise.resolve('<div>1</div>');
}

assert.strictEqual(createElement, h);

// children
Expand All @@ -19,6 +27,32 @@ describe('Runtime behavior of JSX', () => {

// no attributes
assert.equal(createElement('div', null), '<div></div>');

// render Component
assert.equal(createElement(Component, null), '<div></div>');
assert.equal(createElement(Component, {}, 'child'), '<div>child</div>');
assert.equal(
createElement(Component, null, 'child ', 'child2'),
'<div>child child2</div>'
);
assert.equal(
createElement(Component, {}, 'child ', 'child2'),
'<div>child child2</div>'
);

// render tag
assert.equal(
createElement('tag', { of: 'custom-html-tag' }),
'<custom-html-tag></custom-html-tag>'
);

// render async Component
assert.ok(
createElement('div', null, createElement(AsyncComponent, null)) instanceof Promise
);

// void element
assert.equal(createElement('meta', null), '<meta/>');
});

test('jsx', () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/html/test/tags.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ describe('Tags', () => {
assert.equal(<tag of="div" attr />, '<div attr></div>');

assert.equal(<tag of="div" attr></tag>, '<div attr></div>');
assert.equal(
<tag of="div" attr>
<div></div>
<div></div>
</tag>,
'<div attr><div></div><div></div></div>'
);

assert.equal(
<tag of="div" attr>
Expand Down
12 changes: 12 additions & 0 deletions packages/html/test/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ describe('Util', () => {
''
);

for (const i of [
undefined,
Promise.resolve(undefined),
[undefined, Promise.resolve(undefined)],
null,
Promise.resolve(null),
[null, Promise.resolve(null)],
[[[[[[[]]]]]]]
]) {
assert.equal(await Html.contentToString(i), '');
}

assert.equal(await Html.contentsToString([]), '');
});

Expand Down

0 comments on commit d38983e

Please sign in to comment.