Skip to content

TypeError: Cannot read properties of null (reading 'off') during mount when running tests for a wrapper component #81

Closed
@AndrewOttavianoAbb

Description

@AndrewOttavianoAbb

Hello and thank you so much for your work on this project! I am creating a wrapper around the react-signature-canvas and am working on writing jest tests for it with testing-libarary/react. I am simply trying to mount it to ensure it displays properly and am receiving the following error. I'm not passing anything to it besides a ref (created with useRef); I'm not even touching canvasProps (at this point). I am rendering the parent <div /> with a data-testid so that I can grab hold of it in testing-library.

Test Code:

describe('Signature', () => {
  it('Component renders successfully', () => {
    render(<Signature SubmitComponent={() => <div />} />);
    const sigCanvas = screen.getByTestId('react-signature-canvas');

    expect(sigCanvas).toBeInTheDocument();
  });
});

(Signature is my wrapper component, this is what I'm actually rendering <SignatureCanvas ref={canvasRef} {...canvasAttributes} /> but canvasAttributes is null in my test above.)

Stack trace:
 ● Signature › Component renders successfully

    TypeError: Cannot read properties of null (reading 'off')

       5 | describe('Signature', () => {
       6 |   it('Component renders successfully', () => {
    >  7 |     render(<Signature SubmitComponent={() => <div />} />);
         |     ^
       8 |     const sigCanvas = screen.getByTestId('react-signature-canvas');     
       9 |
      10 |     expect(sigCanvas).toBeInTheDocument();

      at t.r.off (../../node_modules/react-signature-canvas/build/index.js:1:3228) 
      at t.value (../../node_modules/react-signature-canvas/build/index.js:1:3771) 
      at callComponentWillUnmountWithTimer (../../node_modules/react-dom/cjs/react-dom.development.js:20413:14)
      at HTMLUnknownElement.callCallback (../../node_modules/react-dom/cjs/react-dom.development.js:3945:14)
      at HTMLUnknownElement.callTheUserObjectsOperation (../../node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30)
      at innerInvokeEventListeners (../../node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:338:25)
      at invokeEventListeners (../../node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:274:3)
      at HTMLUnknownElementImpl._dispatch (../../node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:221:9)
      at HTMLUnknownElementImpl.dispatchEvent (../../node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)
      at HTMLUnknownElement.dispatchEvent (../../node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:231:34)
      at Object.invokeGuardedCallbackDev (../../node_modules/react-dom/cjs/react-dom.development.js:3994:16)
      at invokeGuardedCallback (../../node_modules/react-dom/cjs/react-dom.development.js:4056:31)
      at safelyCallComponentWillUnmount (../../node_modules/react-dom/cjs/react-dom.development.js:20420:5)
      at commitUnmount (../../node_modules/react-dom/cjs/react-dom.development.js:20951:11)
      at commitNestedUnmounts (../../node_modules/react-dom/cjs/react-dom.development.js:21004:5)
      at unmountHostComponents (../../node_modules/react-dom/cjs/react-dom.development.js:21290:7)
      at commitDeletion (../../node_modules/react-dom/cjs/react-dom.development.js:21347:5)
      at commitMutationEffects (../../node_modules/react-dom/cjs/react-dom.development.js:23407:11)
      at HTMLUnknownElement.callCallback (../../node_modules/react-dom/cjs/react-dom.development.js:3945:14)
      at HTMLUnknownElement.callTheUserObjectsOperation (../../node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30)
      at innerInvokeEventListeners (../../node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:338:25)
      at invokeEventListeners (../../node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:274:3)
      at HTMLUnknownElementImpl._dispatch (../../node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:221:9)
      at HTMLUnknownElementImpl.dispatchEvent (../../node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)
      at HTMLUnknownElement.dispatchEvent (../../node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:231:34)
      at Object.invokeGuardedCallbackDev (../../node_modules/react-dom/cjs/react-dom.development.js:3994:16)
      at invokeGuardedCallback (../../node_modules/react-dom/cjs/react-dom.development.js:4056:31)
      at commitRootImpl (../../node_modules/react-dom/cjs/react-dom.development.js:23121:9)
      at unstable_runWithPriority (../../node_modules/scheduler/cjs/scheduler.development.js:468:12)
      at runWithPriority$1 (../../node_modules/react-dom/cjs/react-dom.development.js:11276:10)
      at commitRoot (../../node_modules/react-dom/cjs/react-dom.development.js:22990:3)
      at performSyncWorkOnRoot (../../node_modules/react-dom/cjs/react-dom.development.js:22329:3)
      at ../../node_modules/react-dom/cjs/react-dom.development.js:11327:26        
      at unstable_runWithPriority (../../node_modules/scheduler/cjs/scheduler.development.js:468:12)
      at runWithPriority$1 (../../node_modules/react-dom/cjs/react-dom.development.js:11276:10)
      at flushSyncCallbackQueueImpl (../../node_modules/react-dom/cjs/react-dom.development.js:11322:9)
      at flushSyncCallbackQueue (../../node_modules/react-dom/cjs/react-dom.development.js:11309:3)
      at batchedUpdates$1 (../../node_modules/react-dom/cjs/react-dom.development.js:22387:7)
      at act (../../node_modules/react-dom/cjs/react-dom-test-utils.development.js:1042:14)
      at render (../../node_modules/@testing-library/react/dist/pure.js:97:26)     
      at Object.<anonymous> (src/lib/signature/Signature.spec.tsx:7:5)
      at TestScheduler.scheduleTests (../../node_modules/@jest/core/build/TestScheduler.js:333:13)
      at runJest (../../node_modules/@jest/core/build/runJest.js:404:19)

Rendering in the browser seems to work. Any suggestions as to what I'm doing wrong or is this a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: supportAsking for support with something or a specific use casescope: downstreamIssue in a downstream library, not in this library itselfscope: integrationRelated to an integration, not necessarily to core (but could influence core)solution: can't reproAn attempt to reproduce has been tried and failed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions