Composition API のテストでは
DOM 出力の確認
非同期処理の確認
Vuex(store)の dispatch / commit 呼び出し確認
がメインになる。
→ そのため使うマッチャも
✅ toContain
✅ toHaveBeenCalledWith
✅ resolves
/ rejects
などに偏りがある。
マッチャ | 意味 | 使用例 |
---|---|---|
toBe(value) |
厳密な一致(===) | expect(count.value).toBe(3) |
toEqual(obj) |
オブジェクト・配列の内容一致 | expect({ a: 1 }).toEqual({ a: 1 }) |
toBeTruthy() |
true とみなされるか | expect(wrapper.exists()).toBeTruthy() |
toBeFalsy() |
false とみなされるか | expect(false).toBeFalsy() |
toContain(substring) |
文字列 / 配列に含まれるか | expect(wrapper.text()).toContain('OK') |
マッチャ | 意味 | 使用例 |
---|---|---|
toHaveBeenCalled() |
モック関数が呼ばれた | expect(dispatchMock).toHaveBeenCalled() |
toHaveBeenCalledTimes(n) |
n 回呼ばれた | expect(dispatchMock).toHaveBeenCalledTimes(1) |
toHaveBeenCalledWith(arg) |
指定した引数で呼ばれた | expect(dispatchMock).toHaveBeenCalledWith('increment') |
toMatchSnapshot() |
スナップショットと一致する | expect(wrapper.html()).toMatchSnapshot() |
toMatchInlineSnapshot() |
インラインでスナップショットを記録 | expect(wrapper.html()).toMatchInlineSnapshot(...) |