nandorojo / moti

🐼 The React Native (+ Web) animation library, powered by Reanimated 3.
https://moti.fyi
MIT License
3.91k stars 120 forks source link

Testing with jest #182

Closed vjmanlapaz-nuskin closed 2 years ago

vjmanlapaz-nuskin commented 2 years ago

I'm writing some test for my component using jest, and i came across an issue that says Jest encountered an unexpected token and it's pointing to my moti import.

Im not sure how to fix this. please help.

Screen Shot 2022-03-10 at 10 58 44 PM
nandorojo commented 2 years ago

I’ve never used Jest so I’m not sure, but did you search the other issues? I think this came up before. You might need to transpile Moti.

vjmanlapaz-nuskin commented 2 years ago

i did find the previous issue related to this and tried it out but did not work, i still get the same error.

https://github.com/nandorojo/moti/issues/156

nandorojo commented 2 years ago

the error message says you need to add libs to transform. did you try that?

rvieceli commented 2 years ago

I think you aren't testing the animation, then you need to mock it creating __mocks__/moti.ts with

import { View as MotiView } from 'react-native';
export { MotiView };

If you are using other components or hooks, you need to mock them as well.

kvntzn commented 1 year ago

late to the party but here's how I did it.

jest.mock('moti', () => ({MotiView: () => 'MotiView'}));