Fix Item#insertChildren() error when passing null for some children.

Relates to #1036
This commit is contained in:
Jürg Lehni 2016-06-13 14:16:25 +02:00
parent 693898a5b1
commit 742401a0e1
2 changed files with 19 additions and 1 deletions

View file

@ -2353,7 +2353,7 @@ new function() { // Injection scope for hit-test functions shared with project
// Use the loop also to filter out wrong _type.
for (var i = items.length - 1; i >= 0; i--) {
var item = items[i];
if (_proto && !(item instanceof _proto)) {
if (!item || _proto && !(item instanceof _proto)) {
items.splice(i, 1);
} else {
// Notify parent of change. Don't notify item itself yet,

View file

@ -108,3 +108,21 @@ test('group.insertChildren(0, otherGroup.children)', function() {
return group.children.length;
}, 0);
});
test('group.addChildren()', function() {
var group = new Group();
var children = [new Path(), new Path()];
group.addChildren(children);
equals(group.children.length, 2,
'group.children.length after adding 2 children');
group.removeChildren();
equals(group.children.length, 0,
'group.children.length after removing all children');
children.splice(1, 0, null);
equals(children.length, 3,
'children array length after inserting null at index 1');
group.addChildren(children);
equals(group.children.length, 2,
'calling group.addChildren() with an array with 3 entries, ' +
'of which 2 are valid, group.children.length should be 2');
});