🌊

jestのto~が削除される

2022/09/17に公開

内容

JestのMatcher関数の多くが削除されるみたいです。
具体的には以下。

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();

以下に変更されるよう。

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();

動機

変更理由として、以下のような動機らしいです。
Removing duplicated matchers will return Jest's size a little
・Jestの不要Matchersを削除してサイズを少しでも小さくしたい。

We've already identified the preferred matcher in each set
no-alias-methods provides a migration method, which can be automatically fixed
・すでにfix用のマイグレーションコマンドはあるので、自動修正かけられる。

it's easy to extend the matchers Jest has, so folks can re-alias these themselves if they wish
・JestのMatcher拡張については、必要に応じて再エイリアスすることが容易

eventually this would let external tools (like eslint-plugin-jest) shave off a little complexity i.e. by not having to check for two matchers
・外部ツール(eslint-plugin-jestのような)に対して複数のMatcherを確認する手間を省くことができる。

参考

https://github.com/facebook/jest/issues/13164

https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-alias-methods.md

Discussion