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: Cannot read property 'split' of undefined

See original GitHub issue

during jest test (works fine in normal usage), ant design horizontal menu is throwing TypeError: Cannot read property 'split' of undefined here:

  at node_modules/rc-menu/lib/DOMWrap.js:82:31
          at Array.filter (<anonymous>)
      at DOMWrap._this.getMenuItemNodes (node_modules/rc-menu/lib/DOMWrap.js:81:41)
      at DOMWrap._this.setChildrenWidthAndResize (node_modules/rc-menu/lib/DOMWrap.js:165:33)
      at DOMWrap.componentDidMount (node_modules/rc-menu/lib/DOMWrap.js:227:10)

https://github.com/react-component/menu/blob/master/src/DOMWrap.jsx#L77

The menu in my code has no explicit submenu items defined, its just a single level header menu…though when inspecting I see ant design adding a “ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu” with “display:none;” for no apparent reason. See the first example “Navigation One” here for an example: https://ant.design/components/menu

<ul class="ant-menu ant-menu-light ant-menu-root ant-menu-horizontal" role="menu">
   <!-- Why is this empty submenu even here? -->
   <li class="ant-menu-submenu ant-menu-submenu-horizontal ant-menu-overflowed-submenu" role="menuitem" style="display: none;"><div class="ant-menu-submenu-title" aria-expanded="false" aria-haspopup="true"><span>···</span><i class="ant-menu-submenu-arrow"></i></div></li>
   <li class="ant-menu-item ant-menu-item-selected" role="menuitem"><i class="anticon anticon-mail"><svg viewBox="64 64 896 896" class="" data-icon="mail" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M928 160H96c-17.7 0-32 14.3-32 32v640c0 17.7 14.3 32 32 32h832c17.7 0 32-14.3 32-32V192c0-17.7-14.3-32-32-32zm-40 110.8V792H136V270.8l-27.6-21.5 39.3-50.5 42.8 33.3h643.1l42.8-33.3 39.3 50.5-27.7 21.5zM833.6 232L512 482 190.4 232l-42.8-33.3-39.3 50.5 27.6 21.5 341.6 265.6a55.99 55.99 0 0 0 68.7 0L888 270.8l27.6-21.5-39.3-50.5-42.7 33.2z"></path></svg></i>Navigation One</li>
   ...

Can rc-menu be optimized to not create display:none submenu elements if there are no submenu explicitly defined? or is that an ant design issue?

I am too new to understand why this error only happens during test but is there anything that you think could be done to prevent the Cannot read property 'split' of undefined in this case? It seems related to submenu which I am not using so I am hoping some optimization somehow could avoid the problem entirely.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

7reactions
picodothcommented, Jan 2, 2019

please consider using enzyme.

1reaction
Enalmadacommented, Jan 2, 2019

Switching react-test-renderer to enzyme seems to work! Thank you for your help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prevent cannot read property split of undefined
This error is a TypeError , and it occurs when calling a method, operand, or argument on the wrong data type, or when...
Read more >
How to Prevent cannot read property split of ... - Gopi Gorantala
The "cannot read property 'split' of undefined" error occurs when trying to call split() method on a variable that stores an undefined value....
Read more >
Cannot Read Property 'split' of Undefined - freeCodeCamp
it will throw the TypeError: Cannot read property 'split' of undefined error. The split method. When split is called on a string, it...
Read more >
Uncaught TypeError: Cannot read property 'split' of undefined
Your question answers itself ;) If og_date contains the date, it's probably a string, so og_date.value is undefined.
Read more >
TypeError: Cannot read property 'split' of undefined - JavaScript
So the argument word is coming in as undefined and therefore you can't run split() on it. You can either make sure it...
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