parcel-pixijs-quickstarter icon indicating copy to clipboard operation
parcel-pixijs-quickstarter copied to clipboard

Tests with pixi.js

Open mvpcortes opened this issue 4 years ago • 3 comments

Hi @llorenspujol,

I using your quickstarter for pixjs.

I tried create a test using a class that extends Graphics Pixi class.

But i get the error:

ReferenceError: window is not defined

  at Object.<anonymous> (node_modules/@pixi/polyfill/src/Promise.js:4:1)
  at Object.<anonymous> (node_modules/pixi.js/lib/pixi.js:12:1)

I think i should start a environment with browser to make that tests. However, I do not do it. There is some pattern to do it?

Sorry if this question is so newbie :c)

Thanks by your quickstarter :)

mvpcortes avatar Jul 23 '20 22:07 mvpcortes

Hi @mvpcortes ,

This happens because the 'jest.config.js' has testEnvironment ="node". In order to use window object in your tests you need to change that to 'jsdom'. Maybe 'jsdom' should be the default.

However, just curiosity, why you need your window object? Maybe you could avoid it's usage.

llorenspujol avatar Jul 24 '20 06:07 llorenspujol

Hi @llorenspujol thanks by your help/answer :)

I was trying make a keyboard listener. In the end I make a "Window" stubed/doubled version.

After I need create a listener for Load Pixijs class. I going to make a loading picture. But in this time I cannot run test because the Graphics Pixi class. It need a lot of dependencies and Window class.

(Sorry my english :) )

mvpcortes avatar Jul 27 '20 20:07 mvpcortes

You are welcome:)

Yeah I get it! In my case most of the times I could isolate the callback function from window event listener and test it without the dependency of 'Window'.

I am not in context, but maybe could be useful for you to not stub the Window object and test it on a more 'upper level' (AKA 'integrations test's or 'end-to-end' test or whatever the name it is), just simulating it's inputs for example.

llorenspujol avatar Aug 24 '20 10:08 llorenspujol