jest/no-alias-methods スタイル
何をするか
このルールは、コード内でジェストのドキュメントで使用されている正式な名前のみを使用することを保証します。
なぜ問題か
これらのエイリアスは、次期メジャーバージョンのジェストで削除される予定です - 詳細は 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();このルールに準拠する適切なコードの例:
javascript
expect(a).toHaveBeenCalled();
expect(a).toHaveBeenCalledTimes();
expect(a).toHaveBeenCalledWith();
expect(a).toHaveBeenLastCalledWith();
expect(a).toHaveBeenNthCalledWith();
expect(a).toHaveReturned();
expect(a).toHaveReturnedTimes();
expect(a).toHaveReturnedWith();
expect(a).toHaveLastReturnedWith();
expect(a).toHaveNthReturnedWith();
expect(a).toThrow();このルールは eslint-plugin-vitest と互換性があります。
利用するには、.oxlintrc.json に以下の設定を追加します:
json
{
"rules": {
"vitest/no-alias-methods": "error"
}
}Vitest と一緒に使用する場合の、このルールに違反する不適切なコードの例:
javascript
expect(a).toBeCalled();
expect(a).toBeCalledTimes();
expect(a).not["toThrowError"]();Vitest と一緒に使用する場合の、このルールに準拠する適切なコードの例:
javascript
expect(a).toHaveBeenCalled();
expect(a).toHaveBeenCalledTimes();
expect(a).toHaveBeenCalledWith();
expect(a).toHaveBeenLastCalledWith();
expect(a).toHaveBeenNthCalledWith();
expect(a).toHaveReturned();
expect(a).toHaveReturnedTimes();
expect(a).toHaveReturnedWith();
expect(a).toHaveLastReturnedWith();
expect(a).toHaveNthReturnedWith();
expect(a).toThrow();
expect(a).rejects;
expect(a);使い方
このルールを有効にするには、設定ファイルまたは CLI で以下のいずれかを使用できます:
json
{
"plugins": ["jest"],
"rules": {
"jest/no-alias-methods": "error"
}
}bash
oxlint --deny jest/no-alias-methods --jest-plugin