Jest snapshot test throws "Cannot read properties of null (reading 'scrollWidth')"

182 Views Asked by At

I'm trying to write a snapshot test for one of the component in my app. The component is built with some Antd components like Select.

i get the following error. enter image description here

The tests

import React from 'react'
import renderer from 'react-test-renderer'
import { render,screen } from '@testing-library/react'


const MockTeamManagerBlock = () => {
  return (
    <TeamManagerBlock
      displayName="editor"
      members={members}
      onAdd={jest.fn()}
      onRemove={jest.fn()}
      onRowSelectionChange={jest.fn()}
      onSearch={jest.fn()}
      teamId="teamId"
    />
  )
}

describe('TeamManagerBlock', () => {
  it('matches snapshot', () => {
    const teamManagerBlockComponent = renderer
      .create(<MockTeamManagerBlock />)
      .toJSON()

    expect(teamManagerBlockComponent).toMatchSnapshot()
  })
})

package.json

  "dependencies": {
    "@ant-design/icons": "^4.6.2",
    "@apollo/client": "^3.6.8",
    "antd": "^5.1.0",
    "lodash": "^4.17.21",
    "prop-types": "^15.7.2",
    "react": "^17.0.2",
    "react-router-dom": "^5.2.0",
    "styled-components": "^5.3.0",
  },
  "devDependencies": {
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^12.1.5",
    "babel-jest": "^29.3.1",
    "faker": "^5.5.3",
    "jest": "^29.3.1",
    "jest-axe": "^7.0.0",
    "jest-environment-jsdom": "^29.3.1",
    "react-test-renderer": "17.0.2"
  }
0

There are 0 best solutions below