LoginSignup
4
0

More than 5 years have passed since last update.

ReactNative の NativeModule を Jestで Mock する

Last updated at Posted at 2017-08-24

ReactNativeでJestを使って npm test でテストスクリプトを走らせると、NativeModulesを参照しているモジュールでエラーになることがある。

テストに関係ないモジュールであれば、 mock 関数でダミーの関数を定義しておけば、エラーを回避することができる。これでテストがうまくいった。

例)react-native-video でエラーになった場合

jest.mock('react-native-video', () => 'Video');

参考

Mock native modules using jest.mock
jest: Test suite failed to run, TypeError: Cannot read property 'SHORT' of undefined

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0