Skip to content

Commit

Permalink
version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancahill committed Nov 3, 2015
1 parent 1b90d93 commit a93f0ba
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 18 deletions.
116 changes: 99 additions & 17 deletions lib/eminent.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,43 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de

/** @module eminent */

/**
*
* @private
* @param {nodelist} collection - DOM collection node list
* @return {array}
*/
var _collectionToArray = function _collectionToArray(collection) {
var ary = [];

var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;

try {
for (var _iterator = collection[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var node = _step.value;

ary.push(node);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}

return ary;
};

/**
* @private
* @param {jsdom} node - Node to parse to HTML
Expand All @@ -39,9 +76,32 @@ var _getNodeHTML = function _getNodeHTML(node, children) {
if (!children) {
node.innerHTML = '';
} else {
for (var i = 0; i < node._childNodes.length; i++) {
node._childNodes[i].innerHTML = '';
};
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;

try {
for (var _iterator2 = node.childNodes[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var child = _step2.value;

child.innerHTML = '';
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}

;
}

return node.outerHTML;
Expand Down Expand Up @@ -77,8 +137,7 @@ var _getTreeHTML = function _getTreeHTML(tree, children) {
* @param {boolean} isContent - Compare content
*/
var compareNode = function compareNode(node, tree, hasAttrs, isAttrs, isContent) {
var i = undefined,
nodeChildren = node._childNodes,
var nodeChildren = _collectionToArray(node.childNodes),
treeChildren = tree.children,
isText = node._localName === undefined,
isBody = node._localName === 'body';
Expand All @@ -97,20 +156,43 @@ var compareNode = function compareNode(node, tree, hasAttrs, isAttrs, isContent)
}

if (hasAttrs || isAttrs && !isBody) {
for (i = 0; i < tree._attributes.length; i++) {
var attrName = tree._attributes[i].name,
attrValue = tree._attributes[i].value;

if (hasAttrs) {
if (!node.hasAttribute(attrName)) {
_assert2.default.fail(_getNodeHTML(node, false), _getTreeHTML(tree, false), 'Attribute \'' + attrName + '\' does not exist', '!=');
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;

try {
for (var _iterator3 = tree._attributes[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var attribute = _step3.value;

var attrName = attribute.name,
attrValue = attribute.value;

if (hasAttrs) {
if (!node.hasAttribute(attrName)) {
_assert2.default.fail(_getNodeHTML(node, false), _getTreeHTML(tree, false), 'Attribute \'' + attrName + '\' does not exist', '!=');
}
} else if (isAttrs) {
if (node.getAttribute(attrName) !== attrValue) {
_assert2.default.fail(_getNodeHTML(node, false), _getTreeHTML(tree, false), 'Value of attribute \'' + attrName + '\' is not \'' + attrValue + '\'', '!=');
}
}
} else if (isAttrs) {
if (node.getAttribute(attrName) !== attrValue) {
_assert2.default.fail(_getNodeHTML(node, false), _getTreeHTML(tree, false), 'Value of attribute \'' + attrName + '\' is not \'' + attrValue + '\'', '!=');
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
};
}

;
}

/*
Expand Down Expand Up @@ -159,7 +241,7 @@ var compareNode = function compareNode(node, tree, hasAttrs, isAttrs, isContent)
_assert2.default.fail(_getNodeHTML(node, true), _getTreeHTML(tree, true), 'Different number of DOM child nodes', '!=');
}

for (i = 0; i < nodeChildren.length; i++) {
for (var i in nodeChildren) {
compareNode(nodeChildren[i], treeChildren[i], hasAttrs, isAttrs, isContent);
};
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eminent",
"version": "0.0.4",
"version": "0.0.5",
"description": "A DOM assertions library with Emmet syntax for JavaScript testing",
"main": "lib/eminent.js",
"scripts": {
Expand Down

0 comments on commit a93f0ba

Please sign in to comment.