Skip to content

Commit

Permalink
Update unit tests to account for $$html name
Browse files Browse the repository at this point in the history
  • Loading branch information
developit committed Dec 20, 2020
1 parent b5af312 commit fe82f17
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
9 changes: 7 additions & 2 deletions test/acorn-traverse.test.js
Expand Up @@ -17,7 +17,7 @@ const parse = (code, opts) => Parser.parse(code, { ecmaVersion: 2020, sourceType
/**
* Transform source code using a Babel plugin
* @param {string} code
* @param {Plugin} plugin
* @param {Plugin | [Plugin] | [Plugin, object]} plugin
* @param {object} [options]
*/
function transformWithPlugin(code, plugin, options = {}) {
Expand Down Expand Up @@ -157,7 +157,12 @@ describe('acorn-traverse', () => {
it.each(cases.filter(f => f.match(/\.expected/)))('fixtures', async expectedFile => {
const expected = await fs.readFile(path.join(fixtures, expectedFile), 'utf-8');
const source = await fs.readFile(path.join(fixtures, expectedFile.replace('.expected', '')), 'utf-8');
const actual = transformWithPlugin(source, transformJsxToHtm);
const actual = transformWithPlugin(source, [
transformJsxToHtm,
{
tag: '$$html'
}
]);
expect(actual).toEqual(expected);
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/_unit/jsx-nesting.expected.js
@@ -1,7 +1,7 @@
export function x(y) {
return (
html`
${Object.entries(y).map(([k, v]) => html`<li>
$$html`
${Object.entries(y).map(([k, v]) => $$html`<li>
${k}: ${v}
</li>`)}
`
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/transformations/jsx-escaped.expected.js
@@ -1,4 +1,4 @@
import { html } from '/@npm/htm/preact';
import { html as $$html } from '/@npm/htm/preact';
export function Foo() {
return html`<span>${`<`}</span>`;
return $$html`<span>${`<`}</span>`;
}
6 changes: 3 additions & 3 deletions test/fixtures/transformations/jsx-member.expected.js
@@ -1,13 +1,13 @@
import { html } from '/@npm/htm/preact';
import { html as $$html } from '/@npm/htm/preact';
const Ctx = {
Foo: function Foo() {
return html`<div />`;
return $$html`<div />`;
}
};

export default function Demo() {
return (
html`<${Ctx.Foo} value=${{ foo: 123 }}>
$$html`<${Ctx.Foo} value=${{ foo: 123 }}>
<div />
<//>`
);
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/transformations/jsx.expected.js
@@ -1,4 +1,4 @@
import { html } from '/@npm/htm/preact';
import { html as $$html } from '/@npm/htm/preact';
const LIST = [
{ id: 'one', text: 'item 1', props: {} },
{ id: 'two', text: 'item 2', props: { class: 'foo' } },
Expand All @@ -7,12 +7,12 @@ const LIST = [

export default function Demo({ name = 'Bob', list = LIST }) {
return (
html`<div id="app">
$$html`<div id="app">
<h1>Hello</h1>
<p>Name: ${name}</p>
<ul>
${list.map(item => (
html`<li ...${item.props} key=${item.id}>
$$html`<li ...${item.props} key=${item.id}>
${item.text}
</li>`
))}
Expand Down

0 comments on commit fe82f17

Please sign in to comment.