Skip to content

Commit

Permalink
Add unit tests for Application.ticker setter
Browse files Browse the repository at this point in the history
  • Loading branch information
schipiga committed Mar 3, 2018
1 parent 85aaea5 commit 3c76088
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/core/Application.js
Expand Up @@ -179,11 +179,13 @@ export default class Application
*/
destroy(removeView)
{
const oldTicker = this._ticker;

this.ticker = null;
if (this._ticker)
{
const oldTicker = this._ticker;

oldTicker.destroy();
this.ticker = null;
oldTicker.destroy();
}

this.stage.destroy();
this.stage = null;
Expand Down
64 changes: 64 additions & 0 deletions test/core/Application.js
Expand Up @@ -66,4 +66,68 @@ describe('PIXI.Application', function ()

app.destroy(true);
});

describe('set ticker', function ()
{
const self = this;

before(function ()
{
self.app = new PIXI.Application();
/* remove default listener to prevent uncaught exception */
self.app._ticker.remove(self.app.render, self.app);
});

after(function ()
{
self.app.destroy(true);
});

it('should assign ticker object', function ()
{
const ticker = { add: sinon.spy() };
const _ticker = { remove: sinon.spy() };

self.app._ticker = _ticker;
self.app.ticker = ticker;

expect(_ticker.remove).to.be.calledOnce;
expect(_ticker.remove.args[0][0]).to.be.equal(self.app.render);
expect(_ticker.remove.args[0][1]).to.be.equal(self.app);

expect(self.app._ticker).to.be.equal(ticker);
expect(ticker.add).to.be.calledOnce;
expect(ticker.add.args[0][0]).to.be.equal(self.app.render);
expect(ticker.add.args[0][1]).to.be.equal(self.app);
expect(ticker.add.args[0][2]).to.be.equal(PIXI.UPDATE_PRIORITY.LOW);
});

it('should assign ticker if no ticker', function ()
{
const ticker = { add: sinon.spy() };

self.app._ticker = null;
self.app.ticker = ticker;

expect(self.app._ticker).to.be.equal(ticker);
expect(ticker.add).to.be.calledOnce;
expect(ticker.add.args[0][0]).to.be.equal(self.app.render);
expect(ticker.add.args[0][1]).to.be.equal(self.app);
expect(ticker.add.args[0][2]).to.be.equal(PIXI.UPDATE_PRIORITY.LOW);
});

it('should assign null ticker', function ()
{
const _ticker = { remove: sinon.spy() };

self.app._ticker = _ticker;
self.app.ticker = null;

expect(_ticker.remove).to.be.calledOnce;
expect(_ticker.remove.args[0][0]).to.be.equal(self.app.render);
expect(_ticker.remove.args[0][1]).to.be.equal(self.app);

expect(self.app._ticker).to.be.null;
});
});
});

0 comments on commit 3c76088

Please sign in to comment.