跳至內容

jest/no-alias-methods 樣式

🛠️ 此規則提供自動修正。

此規則的作用

此規則確保程式碼中僅使用 Jest 文件中使用的標準名稱。

為什麼這樣不好?

這些別名將在下一個 Jest 主要版本中移除 - 請參閱 jestjs/jest#13164 以取得更多資訊。此規則將更容易在程式碼中搜尋到方法的所有使用情況,並確保使用的方法名稱之間的一致性。

範例

javascript
expect(a).toBeCalled();
expect(a).toBeCalledTimes();
expect(a).toBeCalledWith();
expect(a).lastCalledWith();
expect(a).nthCalledWith();
expect(a).toReturn();
expect(a).toReturnTimes();
expect(a).toReturnWith();
expect(a).lastReturnedWith();
expect(a).nthReturnedWith();
expect(a).toThrowError();

此規則與 eslint-plugin-vitest 相容,若要使用它,請將以下設定新增至您的 .eslintrc.json

json
{
  "rules": {
    "vitest/no-alias-methods": "error"
  }
}

參考資料

以 MIT 授權釋出。