assert-element
Advanced tools
Comparing version 0.0.3 to 0.1.0
{ | ||
"name": "assert-element", | ||
"version": "0.0.3", | ||
"version": "0.1.0", | ||
"dependencies": { | ||
@@ -5,0 +5,0 @@ "component/assert": "*" |
0.1.0 / 2015-09-11 | ||
================== | ||
* hasAttribute: supporting function argument | ||
0.0.3 / 2015-08-20 | ||
@@ -3,0 +8,0 @@ ================== |
23
index.js
@@ -33,3 +33,9 @@ | ||
assert(attr in node.attributes, 'expected to find the attribute ' + attr + ' in the given node'); | ||
if (value) assert.strictEqual(node.attributes[attr], value); | ||
if (value) { | ||
if (typeof value === 'function') { | ||
value(node.attributes[attr]); | ||
} else { | ||
assert.strictEqual(node.attributes[attr], value); | ||
} | ||
} | ||
}; | ||
@@ -90,3 +96,2 @@ | ||
exports.hasChild = function (node, index, criteria) { | ||
if (arguments.length === 2) criteria = noop; | ||
exports.isNode(node); | ||
@@ -96,8 +101,12 @@ assert(node.children.length > 0, 'provided node has no children'); | ||
assert(index >= 0, 'provided index cannot be negative'); | ||
var child = node.children[index]; | ||
assert(child !== undefined, 'child does not exist at the given index'); | ||
if (typeof criteria === 'function') { | ||
criteria(child); | ||
} else { | ||
assert.deepEqual(child, criteria); | ||
assert(typeof child !== 'undefined', 'child does not exist at the given index'); | ||
if (criteria) { | ||
if (typeof criteria === 'function') { | ||
criteria(child); | ||
} else { | ||
assert.deepEqual(child, criteria); | ||
} | ||
} | ||
@@ -104,0 +113,0 @@ }; |
{ | ||
"name": "assert-element", | ||
"version": "0.0.3", | ||
"version": "0.1.0", | ||
"description": "Assertions for checking virtual nodes used by Deku/React/etc", | ||
@@ -5,0 +5,0 @@ "repository": "dekujs/assert-element", |
@@ -28,2 +28,11 @@ # assert-element | ||
When using a `Function`, it will be invoked with the attribute value. From there, you | ||
can run any other assertion that should throw if the value is invalid. | ||
```js | ||
assert.hasAttribute(<Select options={[ 'a', 'b' ]} />, 'options', function (options) { | ||
assert.deepEqual(options, [ 'a', 'b', 'c' ]); // will fail | ||
}); | ||
``` | ||
**NOTE:** this allows for falsy values, as an attribute can be present but intentionally | ||
@@ -30,0 +39,0 @@ false, such as `checked={false}`. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22061
386
169