3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

expoでtest(jest)するときのセットアップメモ(2019年11月版)

Posted at

expoでjestを使ってテストをする際は原則ここに書いてある通りにすればよい。

しかし、2019年11月2日現在、

npm test

を実行すると、

 Cannot read property 'current' of undefined

というエラーに遭遇。ここの情報によるとreact-test-rendererのバージョンミスマッチのよう。

react-test-rendererのバージョンをreactとかのバージョンと合わせばよいらしい。
最近expoでもライブラリのバージョンミスマッチが多い。。。

package.jsonを変更する。

以下、抜粋。

package.json
  "dependencies": {
    "expo": "^35.0.0",
+    "react": "16.8.3",
+    "react-dom": "16.8.3",
    "react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz",
    "react-native-web": "^0.11.7"
  },
  "devDependencies": {
    "babel-preset-expo": "^7.1.0",
    "firebase-mock": "^2.2.10",
    "jest": "^24.9.0",
    "jest-expo": "^35.0.0",
+    "react-test-renderer": "16.8.3"
  },

わかりやすいように+でハイライトしているが、追加というわけではない。

変更したら再度npm install。再度、npm testで、無事動いた。

メモ

エラーとは関係ないが、下記にfirebase-mockを利用したテスト方法がある。

3
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
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?