phaser
Version:
A fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers from the team at Phaser Studio Inc.
136 lines (118 loc) • 4.74 kB
JavaScript
var ParticleProcessor = require('../../../src/gameobjects/particles/ParticleProcessor');
describe('ParticleProcessor', function ()
{
describe('constructor', function ()
{
it('should create a processor with default values', function ()
{
var processor = new ParticleProcessor();
expect(processor.x).toBe(0);
expect(processor.y).toBe(0);
expect(processor.active).toBe(true);
});
it('should create a processor with custom x and y', function ()
{
var processor = new ParticleProcessor(100, 200);
expect(processor.x).toBe(100);
expect(processor.y).toBe(200);
});
it('should create a processor with custom active state', function ()
{
var processor = new ParticleProcessor(0, 0, false);
expect(processor.active).toBe(false);
});
it('should create a processor with all custom values', function ()
{
var processor = new ParticleProcessor(50, 75, true);
expect(processor.x).toBe(50);
expect(processor.y).toBe(75);
expect(processor.active).toBe(true);
});
it('should have emitter as undefined initially', function ()
{
var processor = new ParticleProcessor();
expect(processor.emitter).toBeUndefined();
});
it('should accept negative coordinates', function ()
{
var processor = new ParticleProcessor(-100, -200);
expect(processor.x).toBe(-100);
expect(processor.y).toBe(-200);
});
it('should accept floating point coordinates', function ()
{
var processor = new ParticleProcessor(1.5, 2.7);
expect(processor.x).toBeCloseTo(1.5);
expect(processor.y).toBeCloseTo(2.7);
});
it('should accept zero for active when passed as falsy', function ()
{
var processor = new ParticleProcessor(0, 0, false);
expect(processor.active).toBe(false);
});
});
describe('update', function ()
{
it('should be a function', function ()
{
var processor = new ParticleProcessor();
expect(typeof processor.update).toBe('function');
});
it('should not throw when called with no arguments', function ()
{
var processor = new ParticleProcessor();
expect(function () { processor.update(); }).not.toThrow();
});
it('should not throw when called with particle, delta, step, and t arguments', function ()
{
var processor = new ParticleProcessor();
var mockParticle = { velocityX: 0, velocityY: 0 };
expect(function () { processor.update(mockParticle, 16, 0.016, 0.5); }).not.toThrow();
});
it('should return undefined', function ()
{
var processor = new ParticleProcessor();
var result = processor.update();
expect(result).toBeUndefined();
});
it('should not modify particle properties by default', function ()
{
var processor = new ParticleProcessor();
var mockParticle = { velocityX: 10, velocityY: 20 };
processor.update(mockParticle, 16, 0.016, 0.5);
expect(mockParticle.velocityX).toBe(10);
expect(mockParticle.velocityY).toBe(20);
});
});
describe('destroy', function ()
{
it('should set emitter to null', function ()
{
var processor = new ParticleProcessor();
processor.emitter = { name: 'mockEmitter' };
processor.destroy();
expect(processor.emitter).toBeNull();
});
it('should not throw when emitter is already null', function ()
{
var processor = new ParticleProcessor();
processor.emitter = null;
expect(function () { processor.destroy(); }).not.toThrow();
expect(processor.emitter).toBeNull();
});
it('should not throw when emitter is undefined', function ()
{
var processor = new ParticleProcessor();
expect(function () { processor.destroy(); }).not.toThrow();
});
it('should not affect x, y, or active properties', function ()
{
var processor = new ParticleProcessor(10, 20, false);
processor.emitter = { name: 'mockEmitter' };
processor.destroy();
expect(processor.x).toBe(10);
expect(processor.y).toBe(20);
expect(processor.active).toBe(false);
});
});
});