Skip to content

Commit

Permalink
Keep XO happy
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechilds committed Mar 11, 2017
1 parent 49cfe2f commit 304b861
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/create-node.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default markup => {
const container = document.createElement('div');
container.innerHTML = markup;
return container.children.length > 1 ? container.children : container.children[0];
}
const container = document.createElement('div');
container.innerHTML = markup;
return container.children.length > 1 ? container.children : container.children[0];
};
34 changes: 17 additions & 17 deletions test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,39 @@ import createNode from '../dist/create-node';
browserEnv();

test('createNode should be a function', t => {
t.is(typeof createNode, 'function');
t.is(typeof createNode, 'function');
});

test('createNode(markup) with one top level element should create an HTMLElement DOM node', t => {
const domNode = createNode('<div></div>');
t.true(domNode instanceof HTMLElement);
const domNode = createNode('<div></div>');
t.true(domNode instanceof HTMLElement);
});

test('createNode(markup) with multiple top level elements should create an HTMLCollection of HTMLElement DOM nodes', t => {
const domNode = createNode('<div></div><div></div>');
t.true(domNode instanceof HTMLCollection);
const domNode = createNode('<div></div><div></div>');
t.true(domNode instanceof HTMLCollection);
});

test('DOM node should match markup', t => {
const markup = `
const markup = `
<div>
<span>hello</span>
<span>world</span>
</div>
`;
const expectedText = ['hello', 'world'];
const domNode = createNode(markup);
const expectedText = ['hello', 'world'];
const domNode = createNode(markup);

t.true(domNode instanceof HTMLDivElement);
t.is(domNode.children.length, 2);
Array.from(domNode.children).forEach((childNode, i) => {
t.true(childNode instanceof HTMLSpanElement);
t.is(childNode.textContent, expectedText[i]);
});
t.true(domNode instanceof HTMLDivElement);
t.is(domNode.children.length, 2);
Array.from(domNode.children).forEach((childNode, i) => {
t.true(childNode instanceof HTMLSpanElement);
t.is(childNode.textContent, expectedText[i]);
});
});

test('DOM node should insert into DOM', t => {
const domNode = createNode('<div></div>');
document.body.appendChild(domNode)
t.is(document.body.lastChild, domNode);
const domNode = createNode('<div></div>');
document.body.appendChild(domNode);
t.is(document.body.lastChild, domNode);
});

0 comments on commit 304b861

Please sign in to comment.