parcel-pixijs-quickstarter
parcel-pixijs-quickstarter copied to clipboard
Tests with pixi.js
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 :)
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.
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 :) )
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.