diff --git a/test/core/Container.js b/test/core/Container.js index e0001ea..11aaebd 100644 --- a/test/core/Container.js +++ b/test/core/Container.js @@ -180,6 +180,47 @@ expect(() => container.getChildAt(1)).to.throw('getChildAt: Index (1) does not exist.'); }); }); + + describe('setChildIndex', () => + { + it('should throw on out-of-bounds', () => + { + const container = new PIXI.Container(); + const child = new PIXI.DisplayObject(); + + container.addChild(child); + + expect(() => container.setChildIndex(child, -1)).to.throw('The supplied index is out of bounds'); + expect(() => container.setChildIndex(child, 1)).to.throw('The supplied index is out of bounds'); + }); + + it('should throw when child does not belong', () => + { + const container = new PIXI.Container(); + const child = new PIXI.DisplayObject(); + + container.addChild(new PIXI.DisplayObject()); + + expect(() => container.setChildIndex(child, 0)) + .to.throw('The supplied DisplayObject must be a child of the caller'); + }); + + it('should set index', () => + { + const container = new PIXI.Container(); + const child = new PIXI.DisplayObject(); + + container.addChild(child, new PIXI.DisplayObject(), new PIXI.DisplayObject()); + expect(container.children.indexOf(child)).to.be.equals(0); + + container.setChildIndex(child, 1); + expect(container.children.indexOf(child)).to.be.equals(1); + + container.setChildIndex(child, 2); + expect(container.children.indexOf(child)).to.be.equals(2); + + container.setChildIndex(child, 0); + expect(container.children.indexOf(child)).to.be.equals(0); }); });