Skip to content

Add tests for TilingSprite.getLocalBounds#4752

Merged
bigtimebuddy merged 5 commits intopixijs:devfrom
schipiga:tests/tiling-sprite
May 24, 2018
Merged

Add tests for TilingSprite.getLocalBounds#4752
bigtimebuddy merged 5 commits intopixijs:devfrom
schipiga:tests/tiling-sprite

Conversation

@schipiga
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Collaborator

@ivanpopelyshev ivanpopelyshev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, WHAT? I thought we fixed it.

this._bounds.minY = this._height * -this._anchor._y;
this._bounds.maxX = this._width * (1 - this._anchor._x);
this._bounds.maxY = this._height * (1 - this._anchor._x);
this._bounds.maxY = this._height * (1 - this._anchor._y);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, good find!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks :)

Comment thread test/core/TilingSprite.js Outdated
this.tileSprite._anchor = {
_x: 3,
_y: 4,
};
Copy link
Copy Markdown
Member

@bigtimebuddy bigtimebuddy Mar 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I'm not really a fan how anti-pattern the code in your tests are. Why are you not doing this.tilingSprite.anchor.set(3, 4) here or setting width and height in the TilingSprite constructor in before? It's not good form to set private variables, similar to my comment in your last PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I will fix it

Comment thread test/core/TilingSprite.js Outdated

after(function ()
{
this.tileSprite.children = [];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't re-assign children. this.tileSprite.children.length = 0

Comment thread test/core/TilingSprite.js

beforeEach(function ()
{
sinon.stub(PIXI.Sprite.prototype, 'getLocalBounds');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why PIXI.Sprite.prototype and not TIlingSprite's prototype?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because return super.getLocalBounds.call(this, rect);, calls PIXI.Sprite.prototype.getLocalBounds, not PIXI.extras.TilingSprite.prototype.getLocalBounds.

For experiment, I changed sinon.stub(PIXI.Sprite.prototype, 'getLocalBounds'); to sinon.stub(PIXI.extras.TilingSprite.prototype, 'getLocalBounds'); and had got failed tests, as expected.

@schipiga schipiga force-pushed the tests/tiling-sprite branch from 9aeb6d2 to 0789332 Compare March 11, 2018 08:01
@schipiga schipiga force-pushed the tests/tiling-sprite branch from 0789332 to db9bb6c Compare March 11, 2018 08:05
Comment thread test/core/TilingSprite.js Outdated
this.tileSprite._anchor = {
_x: 3,
_y: 4,
};
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I will fix it

Comment thread test/core/TilingSprite.js

beforeEach(function ()
{
sinon.stub(PIXI.Sprite.prototype, 'getLocalBounds');
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because return super.getLocalBounds.call(this, rect);, calls PIXI.Sprite.prototype.getLocalBounds, not PIXI.extras.TilingSprite.prototype.getLocalBounds.

For experiment, I changed sinon.stub(PIXI.Sprite.prototype, 'getLocalBounds'); to sinon.stub(PIXI.extras.TilingSprite.prototype, 'getLocalBounds'); and had got failed tests, as expected.

Comment thread test/core/TilingSprite.js
before(function ()
{
this.tileSprite = new PIXI.extras.TilingSprite(PIXI.Texture.EMPTY, 1, 2);
this.tileSprite.anchor.set(3, 4);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, it's simplier to manage used properties (even private) directly, than to make test depending from another method like anchor.set(x, y). Because if it will be wrong, the target test will be wrong too, which looks more like integration testing, than unittesting.
But of course, here I will follow project guidelines.

this._bounds.minY = this._height * -this._anchor._y;
this._bounds.maxX = this._width * (1 - this._anchor._x);
this._bounds.maxY = this._height * (1 - this._anchor._x);
this._bounds.maxY = this._height * (1 - this._anchor._y);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks :)

@bigtimebuddy bigtimebuddy added this to the v4.8.0 milestone Mar 15, 2018
@bigtimebuddy bigtimebuddy added Domain: Tests 🥶 Low Priority Generally issues or PRs that don’t need to make it into the next release. labels Apr 9, 2018
@bigtimebuddy bigtimebuddy merged commit f61a5a0 into pixijs:dev May 24, 2018
bigtimebuddy pushed a commit that referenced this pull request May 24, 2018
@lock
Copy link
Copy Markdown

lock Bot commented May 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock Bot locked and limited conversation to collaborators May 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

🥶 Low Priority Generally issues or PRs that don’t need to make it into the next release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants