🎯 A. Jest マッチャ一覧(Composition API でよく使うもの)


✅ 【要点】

Composition API のテストでは

→ そのため使うマッチャも

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')

🟠 【Vue コンポーネント特有でよく使うもの】

マッチャ 意味 使用例
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(...)

🟣 【非同期処理用】