jestとは facebookが作ったテストフレームワークです。 automockという特殊な機能を持っていて、すべてのモジュールがモック化された状態でロードされます。 今回は、automockの使い方を書いておきます。 automockを使ったテストの書き方 まずは、jest用のconfigファイルを用意します。 package.jsonか、適当なjsonファイルに記述することができます。 package.jsonに書く場合は以下のとおり。
import { hogefuga } from "../app"; import { hoge, fuga } from "../utils"; jest.unmock("../app"); describe("app", () => { describe("#hogefuga", () => { describe("hoge, fuga returns hoge each.", () => { beforeAll(() => { // hoge, fugaは // https://facebook.github.io/jest/docs/en/mock-function-api.html // ↑に記述されているmockに置き換わっています。 hoge.mockReturnValue("hoge"); // hogeを返すように設定しておいたり fuga.mockImplementat
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く