jollyjerr / react-autosave

Component or hook to auto save controlled form values as they are updated
https://www.npmjs.com/package/react-autosave
MIT License
65 stars 2 forks source link

Unable to mock useAutosave hook since 0.4.0 #16

Closed ockam closed 1 year ago

ockam commented 2 years ago

Just installed the 0.4.0 update (thanks for the quick update) and the useAutosave hook mock (jest-mock) I was using in my tests stopped working.

It fails with the error Failed to get mock metadata: [...]/node_modules/react-autosave/dist/react-autosave.umd.js.

I’m no test guru, so I don’t have a fix to suggest, but I continue trying to find a workaround on my end.

jollyjerr commented 2 years ago

Thank you for letting me know 👍🏼 Might be best to downgrade until I can get a fix.

ockam commented 2 years ago

Explicitly defining the mock does the trick:

jest.mock('react-autosave', () => ({ useAutosave: jest.fn() }))

jollyjerr commented 2 years ago

Nice! I will try to get it working again in the future anyway. What major version of jest are you using? 26, 27, or 28?

ockam commented 2 years ago

Jest 27.5.1 with React 17.0.2

jollyjerr commented 1 year ago

This should be fixed in 0.4.2