add findWhere method to Containers

This commit is contained in:
Adam L
2018-03-21 19:03:38 -07:00
parent 248f57cd3f
commit 8bb59548e5
3 changed files with 78 additions and 0 deletions

View File

@@ -406,6 +406,37 @@ suite('Container', function() {
);
});
// ======================================================
test('select shape by function', function() {
var stage = addStage();
var layer = new Konva.Layer();
var rect = new Konva.Rect({
x: 300,
y: 100,
width: 100,
height: 50,
fill: 'purple',
stroke: 'black',
strokeWidth: 4,
name: 'myRect'
});
layer.add(rect);
stage.add(layer);
var fn = function(node) {
return node.nodeType === 'Shape';
};
var noOp = function(node) {
return false;
};
assert.equal(stage.findWhere(fn)[0], rect);
assert.equal(stage.findWhere(noOp).length, 0);
});
// ======================================================
test('set x on an array of nodes', function() {
var stage = addStage();