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.

TypeError: Illegal invocation when running app tests with jest

See original GitHub issue
● Test suite failed to run

    TypeError: Illegal invocation

      at Node.get [as childNodes] (node_modules/jsdom/lib/jsdom/living/generated/Node.js:423:13)
      at Node.get (node_modules/smooth-dnd/dist/index.js:1:15997)
      at node_modules/smooth-dnd/dist/index.js:1:15891
      at Object.<anonymous> (node_modules/smooth-dnd/dist/index.js:1:16064)
      at Object.<anonymous> (node_modules/smooth-dnd/dist/index.js:1:16414)
      at n (node_modules/smooth-dnd/dist/index.js:1:358)
      at Object.<anonymous> (node_modules/smooth-dnd/dist/index.js:1:16522)
      at Object.<anonymous> (node_modules/smooth-dnd/dist/index.js:1:23545)
      at n (node_modules/smooth-dnd/dist/index.js:1:358)
      at Object.<anonymous> (node_modules/smooth-dnd/dist/index.js:1:23661)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10

github_iconTop GitHub Comments

7reactions
alexandreDavidcommented, Feb 19, 2019

I added this to the setup.js and it works:

Object.defineProperty(global, 'Node', {
  value: {firstElementChild: 'firstElementChild'}
})
6reactions
leotabosacommented, Aug 4, 2021

Mocking the library is a solution if that’s ok to you.

https://jestjs.io/docs/manual-mocks#mocking-node-modules

//  smooth-dnd.js or vue-smooth-dnd.js inside __mocks__ folder

module.exports = {
  // some mock implementation
}

Solves the problem and as a plus we don’t mess with the environment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest.spyOn Illegal invocation - Stack Overflow
When running npm test , I am getting this Illegal invocation TypeError: Illegal invocation 16 | test("test", async () => { 17 |...
Read more >
cypress-io/cypress - Gitter
Error: Uncaught TypeError: Illegal invocation (https://app.listen360.localhost/ ... Hello, is it a well known problem, that when cypress tests are run in ...
Read more >
Strict mode - JavaScript - MDN Web Docs
JavaScript's strict mode is a way to opt in to a restricted variant of JavaScript, thereby implicitly opting-out of "sloppy mode".
Read more >
Illegal invocation when trying to focus element in React-Reactjs
import React from "react"; export default function App() { const [activeInput, setActiveInput] = React.useState() if (activeInput) activeInput.el.focus() ...
Read more >
Node.js v19.3.0 Documentation
_unrefActive(); DEP0128: modules with an invalid main entry and an index.js ... Mocking; run([options]); test([name][, options][, fn]); describe([name][, ...
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