Skip to content
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

Error: Uncaught [TypeError: Cannot read property 'addEventListener' of null] thrown when using component in tests #78

Closed
jayce1996 opened this issue Oct 13, 2020 · 2 comments

Comments

@jayce1996
Copy link

Whilst my code executes both in the react dev environment, and in a live build, for some bizarre reason I get this error when running jest tests, even the simplest components that contain nothing other than a div and then a bare bones implementation of multiselect-react-dropdown will throw this error when trying to create a jest snapshot.

the following errors are observed:
TypeError: Cannot read property 'addEventListener' of null

  41 | describe('Check CommentTypeSelector snapshot', () => {
  42 |     test('Basic snapshot of CommentTypeSelector', () => {
> 43 |         const app = renderer.create(<Provider store={store}>
     |                              ^
  44 |             <div>
  45 |                 <CommentTypeSelector
  46 |                     setCommentTypes={setCommentTypes}

  at t.value (node_modules/multiselect-react-dropdown/build/index.js:1:18020)
  at commitLifeCycles (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:10428:22)
  at commitLayoutEffects (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:13295:7)
  at HTMLUnknownElement.callCallback (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:9972:14)
  at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:193:27)
  at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
  at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
  at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:30:27)
  at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:157:21)
  at Object.invokeGuardedCallbackDev (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:10021:16)
  at invokeGuardedCallback (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:10073:31)
  at commitRootImpl (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:13033:9)
  at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:653:12)
  at runWithPriority (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:1775:10)
  at commitRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:12873:3)
  at finishSyncRender (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:12384:3)
  at performSyncWorkOnRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:12370:7)
  at node_modules/react-test-renderer/cjs/react-test-renderer.development.js:1825:24
  at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:653:12)
  at runWithPriority (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:1775:10)
  at flushSyncCallbackQueueImpl (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:1820:7)
  at flushSyncCallbackQueue (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:1808:3)
  at scheduleUpdateOnFiber (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11776:9)
  at updateContainer (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:14747:3)
  at Object.create (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:15455:5)
  at Object.test (src/CommentTypeSelector.test.jsx:43:30)
@srigar
Copy link
Owner

srigar commented Feb 23, 2022

Fix available in v2.x.x. Reopen it, if doesnt woork

@srigar srigar closed this as completed Feb 23, 2022
@alex-akanthas
Copy link

@srigar I'm still getting this error with version 2.0.25 and jest

/**
 * @jest-environment jsdom
 */

import renderer from 'react-test-renderer';
import { Multiselect } from 'multiselect-react-dropdown';
 
it('multiselect renders', () => {
    let state = {
        options: [{name: 'Option 1', id: 1},{name: 'Option 2', id: 2}]
    };
    

 
  const tree = renderer
    .create(<Multiselect
            options={state.options} // Options to display in the dropdown
            displayValue="name" // Property name to display in the dropdown options
      />
)
    .toJSON();
  expect(tree).toMatchSnapshot();
});

Any help would be much appreciated. The component itself works great with some nice fixes being observed after we upgraded from 1.6 to 2.0.25 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants