diff --git a/test/core/Container.js b/test/core/Container.js index 11aaebd..e64bc1a 100644 --- a/test/core/Container.js +++ b/test/core/Container.js @@ -58,6 +58,17 @@ assertRemovedFromParent(parent, container, child, () => { container.addChild(child); }); }); + + it('it should call onChildrenChange', () => + { + const container = new PIXI.Container(); + const child = new PIXI.DisplayObject(); + + assertCallToOnChildrenChanged(container, 0, () => + { + container.addChild(child); + }); + }); }); describe('removeChildAt', () => @@ -69,6 +80,19 @@ assertRemovedFromParent(parent, null, child, () => { parent.removeChildAt(0); }); }); + + it('it should call onChildrenChange', () => + { + const container = new PIXI.Container(); + const child = new PIXI.DisplayObject(); + + container.addChild(child); + + assertCallToOnChildrenChanged(container, 0, () => + { + container.removeChildAt(0); + }); + }); }); describe('addChildAt', () => @@ -116,6 +140,19 @@ assertRemovedFromParent(parent, container, child, () => { container.addChildAt(child, 0); }); }); + + it('it should call onChildrenChange', () => + { + const container = new PIXI.Container(); + const child = new PIXI.DisplayObject(); + + container.addChild(new PIXI.DisplayObject()); + + assertCallToOnChildrenChanged(container, 0, () => + { + container.addChildAt(child, 0); + }); + }); }); describe('removeChild', () => @@ -146,6 +183,19 @@ expect(container.children.length).to.be.equals(0); }); + + it('it should call onChildrenChange', () => + { + const container = new PIXI.Container(); + const child = new PIXI.DisplayObject(); + + container.addChild(child); + + assertCallToOnChildrenChanged(container, 0, () => + { + container.removeChild(child); + }); + }); }); describe('getChildIndex', () => @@ -222,8 +272,36 @@ container.setChildIndex(child, 0); expect(container.children.indexOf(child)).to.be.equals(0); }); + + it('it should call onChildrenChange', () => + { + const container = new PIXI.Container(); + const child = new PIXI.DisplayObject(); + + container.addChild(child, new PIXI.DisplayObject()); + + assertCallToOnChildrenChanged(container, 1, () => + { + container.setChildIndex(child, 1); + }); + }); }); + function assertCallToOnChildrenChanged(container, smallestIndex, functionToAssert) + { + let triggered = false; + + container.onChildrenChange = (index) => + { + triggered = true; + expect(index).to.be.equals(smallestIndex) + }; + + functionToAssert(); + + expect(triggered).to.be.true; + } + function assertRemovedFromParent(parent, container, child, functionToAssert) { parent.addChild(child);