Skip to content

Commit

Permalink
Tests: Add test for invalid children
Browse files Browse the repository at this point in the history
  • Loading branch information
fluvf committed Mar 5, 2019
1 parent 2fff651 commit 1806e47
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ test('Pass invalid elements / tagnames ([nothing], \'\', null, undefined, {}, [n
'no element was created');

testInput.map(function (value) {
testElement = undefined;
testElement = undefined;
t.doesNotThrow(function () { testElement = crel(value); },
'Pass invalid input: `' + value + '`');
// Not returning an element on invalid input should be sane behaviour
Expand All @@ -179,6 +179,25 @@ test('Pass invalid elements / tagnames ([nothing], \'\', null, undefined, {}, [n
});
});

test('Pass invalid children (null, undefined)', function (t) {
var testElement = crel('div');
var testedElement;
// ? should empty strings be ignored? Adding empty text nodes only bloats childNodes
// ? what about functions and objects as children
var testInput = [null, undefined];

t.plan(testInput.length * 2); // 2 tests for every value in array

testInput.map(function (value) {
t.doesNotThrow(function () { testedElement = crel('div', value); },
'Pass invalid child argument: `' + value + '`');
// Ignoring invalid children should be sane behaviour
t.ok(testElement.isEqualNode(testedElement),
'Elements have the same child tree');
testedElement = undefined;
});
});

// -- Test exposed methods --
test('Test that `isNode` is defined', function (t) {
// Assign into a variable to help readability
Expand Down

0 comments on commit 1806e47

Please sign in to comment.