question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to require() to use with Jest

See original GitHub issue
TypeError: Cannot read property 'prototype' of undefined
      
      at ../../../../node_modules/c3/c3.js:2720:30
      at ../../../../node_modules/c3/c3.js:3263:3
      at Object.<anonymous>.CLASS.target (../../../../node_modules/c3/c3.js:2:82)
      at Object.<anonymous> (../../../../node_modules/c3/c3.js:5:2)

which is

        window.SVGPathElement.prototype.createSVGPathSegClosePath = function () {

I’m not quite sure where to report this. Jest, jsdom, here?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

26reactions
emrebsonmezcommented, Oct 5, 2017

@fernandes Got it. I played around with it a bit more and was able to run the snapshot tests by mocking c3:

// __mocks__/c3.js
module.exports = () => 'c3';

and then in the Jest config portion of my package.json:

"moduleNameMapper": {
  "c3": "<rootDir>/__mocks__/c3.js",
}
1reaction
kt3kcommented, Sep 21, 2017

@brandonros If you don’t need c3 functionality in your jest test cases, I think it’s ok to replace SVGPathElement with dummy object.

I was able to require c3.js in node environment by dummying window.SVGPathElement like the below:

var JSDOM = require('jsdom').JSDOM;
global.window = new JSDOM().window;
window.SVGPathElement = function () {};
console.log(require('c3')); // => no error!
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to run JEST test - Stack Overflow
I'm facing an issue when I try to import something using require() function in jest test file. script2.test.js
Read more >
Configuring Jest
If a given module's path matches any of the patterns, it will not be require() -able in the test environment. These pattern strings...
Read more >
Configuring package.json · Jest
If you'd like to use your package.json to store Jest's config, the "jest" key should be used on ... it will not be...
Read more >
Writing API Tests with Jest - Rithm School
We can do this from a TDD perspective so let's write some failing tests first! In our first.test.js file let's add: const letterCount...
Read more >
Test runner with Nodejs and Jest not working with 17.1
Test run finished: 2 Tests (0 Passed, 2 Failed, 0 Skipped) run in 1,6 sec ... you need answers to common questions or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found