mock function onClick test failing

Viewed 14

I am using react-testing-libray and trying to mock, or call an onClickHandler function. Is there something wrong with my implementation?

import { onClickHandler } from '../components/etc'

jest.mock('../components/etc', () => ({
    OnClickHandler: jest.fn()
}))

describe("Component", () => {
    beforeEach(() => {
        render(
          <Component />
        )
    })

    test('It shows a button to activate onClick handler', () => {
        const button = screen.getByText('Continue')
        fireEvent.click(button)
        expect(onClickHandler).toHaveBeenCalled()
    })

})
const onClickHandler = () => {
    if (blah blah) {
       do this...
    }
};
   Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

      20 | describe("Component", () => {
      21 |     beforeEach(() => {
    > 22 |         render(
         |         ^
      23 |              <Component />

0 Answers
Related