New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object with three.js WebGLRenderer importing error #3905

Closed
geekplux opened this Issue Jun 25, 2017 · 1 comment

Comments

Projects
None yet
3 participants
@geekplux

geekplux commented Jun 25, 2017

  • jest version: 20.0.4
  • node version: 8.0.0
  • yarn version: 0.21.3
  • npm version: 5.0.3

Do you want to request a feature or report a bug?

It may be a bug.

What is the current behavior?

I created a class with a render function and set a Three.js renderer in it. like below:

class Netjsongraph {
  render () {
    const renderer = new THREE.WebGLRenderer({
      alpha: true,
      antialias: true   // perform antialiasing
    });
}

https://github.com/netjson/netjsongraph.js/blob/dev/src/netjsongraph.three.js#L174-L177

testing code:

import Netjsongraph from '../src/netjsongraph.three.js';

test('Module importing', () => {
  expect(Netjsongraph).toBeDefined();
  expect(new Netjsongraph()).toBeInstanceOf(Netjsongraph);
});

there is no error when run jest.

What is the expected behavior?

I want to abstract this property to a default value of this class. like below:

const defaults = {
  renderer: new THREE.WebGLRenderer({
    alpha: true,
    antialias: true   // perform antialiasing
  })
};

class Netjsongraph {
   constructor () {
      this.renderer = defaults.renderer
   }
}

https://github.com/netjson/netjsongraph.js/blob/0d04f6912bbae2a9f6597eb1157cb84255ab6c8a/src/netjsongraph.three.js#L36-L39

but there is a error occur when I run jest (include jest --no-cache, jest --env=jsdom):

 FAIL  tests/api.spec.js
  ● Test suite failed to run

    TypeError: Cannot read property 'getExtension' of null

      at Object.get (node_modules/three/build/three.js:19663:21)
      at new WebGLRenderer (node_modules/three/build/three.js:20096:14)
      at Object.<anonymous> (src/netjsongraph.three.js:36:13)
      at Object.<anonymous> (tests/api.spec.js:1:128)
          at <anonymous>

    .....

  console.log node_modules/three/build/three.js:19874
    THREE.WebGLRenderer 85

  console.error node_modules/three/build/three.js:20090
    THREE.WebGLRenderer: Error creating WebGL context.

This might because there is no WebGL context in test environment, So how to fix it?

@yqrashawn

This comment has been minimized.

Show comment
Hide comment
@yqrashawn

yqrashawn Aug 19, 2017

I believe this is more like a feature request.

The jsdom environment does not have webgl context. If your tests are focus on scripts rendering data rather than other scripts, you better chose those test framework that run in browser.
So you need to mock those functions that need render context or send data to render context, and focus on other parts of scripts.

Just checked three.js, they don't have test for render scripts either.

yqrashawn commented Aug 19, 2017

I believe this is more like a feature request.

The jsdom environment does not have webgl context. If your tests are focus on scripts rendering data rather than other scripts, you better chose those test framework that run in browser.
So you need to mock those functions that need render context or send data to render context, and focus on other parts of scripts.

Just checked three.js, they don't have test for render scripts either.

@thymikee thymikee closed this Feb 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment