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.

Enzyme tests failing with UncontrolledTooltip

See original GitHub issue

Issue description

  • components: UncontrolledTooltip
  • reactstrap version 5.0.0-alpha.4
  • import method es
  • react version 16.2.0

What is happening?

Enzyme tests are failing when UncontrolledTooltips are used, but the render is working completely fine as expected

What should be happening?

Enzyme tests should pass

Error message in console

The target 'UncontrolledTooltipExample' could not be identified in the dom, tip: check spelling

      at getTarget (node_modules/reactstrap/dist/reactstrap.cjs.js:135:13)
      at Tooltip.componentDidMount (node_modules/reactstrap/dist/reactstrap.cjs.js:4062:22)
      at commitLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:8770:24)
      at commitAllLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:9946:9)
      at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:542:14)
      at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:219:27)
      at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:126:9)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:87:17)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:36:27)
      at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:61:35)
      at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:581:16)
      at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:438:27)
      at commitRoot (node_modules/react-dom/cjs/react-dom.development.js:10050:9)
      at performWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:11017:42)
      at performWork (node_modules/react-dom/cjs/react-dom.development.js:10967:7)
      at requestWork (node_modules/react-dom/cjs/react-dom.development.js:10878:7)
      at scheduleWorkImpl (node_modules/react-dom/cjs/react-dom.development.js:10732:11)
      at scheduleWork (node_modules/react-dom/cjs/react-dom.development.js:10689:12)
      at scheduleTopLevelUpdate (node_modules/react-dom/cjs/react-dom.development.js:11193:5)
      at Object.updateContainer (node_modules/react-dom/cjs/react-dom.development.js:11231:7)
      at node_modules/react-dom/cjs/react-dom.development.js:15226:19
      at Object.unbatchedUpdates (node_modules/react-dom/cjs/react-dom.development.js:11102:12)
      at renderSubtreeIntoContainer (node_modules/react-dom/cjs/react-dom.development.js:15225:17)
      at Object.render (node_modules/react-dom/cjs/react-dom.development.js:15290:12)
      at Object.render (node_modules/enzyme-adapter-react-16/build/ReactSixteenAdapter.js:220:50)
      at new ReactWrapper (node_modules/enzyme/build/ReactWrapper.js:98:16)
      at mount (node_modules/enzyme/build/mount.js:19:10)
      at Object.<anonymous>.it (src/App.test.js:13:21)
          at new Promise (<anonymous>)
      at Promise.resolve.then.el (node_modules/p-map/index.js:46:16)
          at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:160:7)

  ✕ renders without crashing (6ms)

Code

Here’s a brand new create-react-app application demonstrating this issue https://github.com/karthikiyengar/reactstrap-error

npm run test to run Enzyme

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
karthikiyengarcommented, Dec 15, 2017

Many thanks!

it('renders without crashing', () => {
  const div = document.createElement('div');
  div.setAttribute("id", "UncontrolledTooltipExample")
  document.body.appendChild(div)
  mount(<App/>);
});

This does the trick 😃

3reactions
ghostcommented, May 11, 2020

@karthikiyengar , ur answer works for only one tooltip, If there are dynamic Uncontrolled tooltips (data is dynamic) , my page is crashing during the test

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - How to create an unit test for UncontrolledTooltip from ...
If I want to implement an unit test (e.g. jest + enzyme ) for testing its state as either open or close, how...
Read more >
Top 5 enzyme-adapter-react-16 Code Examples - Snyk
How to use enzyme-adapter-react-16 - 10 common examples. To help you get started, we've selected a few enzyme-adapter-react-16 examples, based on popular ...
Read more >
[Solved]-Testing specific MaterialUI Icon-Reactjs
Was able to test this by rendering the Material UI icon, grabbing the inner html, then comparing it to my components icon.
Read more >
React Unit Testing with Enzyme and Jest Part 2 (P5D52)
Project 5 Day 52: Today we will write some unit tests for our React components using Enzyme and Jest.See a professional front-end developer ......
Read more >
Jest Test with Enzyme and Shallow - YouTube
It covers Test Driven Development (TDD) basics with Jest and Enzyme. A major theme is how to focus on one component at a...
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