0
1

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 3 years have passed since last update.

MacBookでReactNativeの開発環境を整える

Last updated at Posted at 2021-12-14

環境

MacBook air m1チップ
macOS Monterey 12.0.1

nodejsのインストールの前に

nvsをインストール。
nodeのバージョンを管理してくれるやつ。
下記からmac用のインストールコマンドをコピペ。

Macの場合PATHを通す必要がある

Macの場合、nvsやnodejsをインストールしたあと、ターミナルを削除してまた起動したあと、
nvs --versionのようにnvsコマンドが使えなくなる。
これはPATHが通ってないために起こる。
そこで、自分のアカウントの直下に.zshrcというファイルがあるので、そこに下記を追加しておく。

export NVS_HOME="$HOME/.nvs"
[ -s "$NVS_HOME/nvs.sh" ] && . "$NVS_HOME/nvs.sh"
nvs use 16.13.0

Jestを導入する

npm install --save-dev jest

pacage.jsonのscriptに下記を追加する。

"test": "jest"

テストしたいときは、

npm test

でテストが走る。

参考にした記事。

Enzymeを導入する。

EnzymeはReactコンポーネントをレンダリングするためのライブラリ。

実際にテストしてみる

関数のテスト

sum.jsファイルを作成する。

function sum(a, b) {
  return a + b;
}
module.exports = sum;

sum.test.jsファイルを作成する。

const sum = require('./sum');

test('adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toBe(3);
});
npm test

を実行すると、テスト結果が表示される。

スクリーンショット 2021-12-12 21.41.53.png

スナップショットテスト

UIのテスト。予期しないUIの変更をテストすることができる。

算術関数や書式変換関数のテストなどはイメージつくけど、スナップショットのテストの重要さはいまだによくわかっていない。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?