From a93f0ba29e6c312ecfe42cb433f05c6f2e06a89e Mon Sep 17 00:00:00 2001 From: Nathan Cahill Date: Tue, 3 Nov 2015 12:03:03 -0700 Subject: [PATCH] version bump --- lib/eminent.js | 116 +++++++++++++++++++++++++++++++++++++++++-------- package.json | 2 +- 2 files changed, 100 insertions(+), 18 deletions(-) diff --git a/lib/eminent.js b/lib/eminent.js index 2ceea84..f4a8e03 100644 --- a/lib/eminent.js +++ b/lib/eminent.js @@ -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 @@ -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; @@ -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'; @@ -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; } } - }; + } + + ; } /* @@ -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); }; }; diff --git a/package.json b/package.json index 445781e..4cb7ab8 100644 --- a/package.json +++ b/package.json @@ -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": {