jeudi 25 février 2021

Jest error after update "Cannot redefine property: useEffect"

Migrating jest from 25 to 26 and react from 16 to 17 resulted in an error for mocking react hooks, as they are not executed with enzyme shallow rendering.

Mocking code:

jest.spyOn(React, 'useEffect').mockImplementationOnce((fn) => fn());

React version: 17.0.1

Error msg:

    TypeError: Cannot redefine property: useEffect
    at Function.defineProperty (<anonymous>)

Does some workaround exist?

Aucun commentaire:

Enregistrer un commentaire