jest/no-interpolation-in-snapshots スタイル
何をするか
スナップショット内での文字列の挿入を使用しないように制限します。
なぜこれは悪いのか
挿入はスナップショットが更新されないようにします。代わりに、プロパティマッチャ を使ってプロパティをマッチャでオーバーロードするべきです。
例
このルールに違反する不適切なコードの例:
javascript
expect(something).toMatchInlineSnapshot(
`Object {
property: ${interpolated}
}`,
);
expect(something).toMatchInlineSnapshot(
{ other: expect.any(Number) },
`Object {
other: Any<Number>,
property: ${interpolated}
}`,
);
expect(errorThrowingFunction).toThrowErrorMatchingInlineSnapshot(`${interpolated}`);このルールは eslint-plugin-vitest と互換性があります。これを使用するには、.oxlintrc.json に以下の設定を追加してください:
json
{
"rules": {
"vitest/no-interpolation-in-snapshots": "error"
}
}使い方
このルールを設定ファイルまたは CLI で有効化するには、次のようにします:
json
{
"plugins": ["jest"],
"rules": {
"jest/no-interpolation-in-snapshots": "error"
}
}bash
oxlint --deny jest/no-interpolation-in-snapshots --jest-plugin