WebGL Detector
Test & mock friendly WebGL detection utility.
Install
npm install --save webgl-detector
Usage
; if // WebGL is supported!// OR for WebGL2if // WebGL2 is supported!
Mocking - Jest & React
Create a file at __mocks__/webgl-detector.js
. Make sure __mocks__
directory is adjacent to node_modules
.
// __mocks__/webgl-detector.jsconst webglDetector = jest; webglDetector { webglDetectorisSupported = value;};webglDetector webglDetectorisSupported;moduleexports = webglDetector;
Suppose we have an Container component named AnimationContainer
and a renderer container named MyAnimation
. If WebGL is supported, AnimationContainer
returns MyAnimation
component:
;; ; const AnimationContainer = <div> ? <MyAnimation ...props /> : <div>WebGL is not supported</div> </div>;;
In our test file:
;
Learn more on mocking Node modules in Jest documentation
License
MIT © Cengiz Can