I'm currently developing a TypeScript/Phaser (2.6.2) project and attempting to run unit tests, set up to use Mocha and Chai (with ts-node/register
and jsdom-global/register
) on a Node environment with node-canvas
installed using the installation instructions for Windows.
The project builds using webpack and runs in the browser correctly, as does Compodoc, and tests that do not require Phaser are also able to execute and pass. Example class/test:
phaser.game.class.ts:
import { Phaser } from 'phaser'
export class Game extends Phaser.Game {
constructor() { super(1280, 720, Phaser.AUTO, 'game') }
}
phaser.game.class.spec.ts:
import 'mocha'
import { expect } from 'chai'
import { Game } from './phaser.game.class'
describe('Game', () => {
it('should be defined', () => {
expect(Game).to.exist
})
})
However when running tests that do import Phaser I receive an error:
context.drawImage(magenta, 0, 0);
^
TypeError: Expected object, number and number
Looking at this issue I believe it may be related to Phaser using a different canvas build to that which is installed with node-canvas
, but I cannot force the use of a certain node-canvas
version (as is described there) as ultimately this will be run in a browser - is this the case, and is there any method to ensure the canvas version just for the tests?
Alternatively I've looked into using phaser-mock and proxyquire (which I would prefer for simply testing isolated class logic), but am experiencing other issues and am unable to find an example implementation combining the two.
Any information would be much appreciated!