引数の検証
引数について検証したいとき
例えば以下のような class があり、UpdateProfileUseCase に渡された profile が正しいか test したいとします。
class ProfileViewModel {
ProfileViewModel({
required Profile profile,
required UpdateProfileUseCase updateProfileUseCase,
}) : _profile = profile,
_updateProfileUseCase = updateProfileUseCase;
Profile _profile;
final UpdateProfileUseCase _updateProfileUseCase;
void onNameChanged(String name) {
_profile = _profile.copyWith(name: name);
}
void onSubmitTapped() {
_updateProfileUseCase.execute(_profile);
}
}
class Profile {
const Profile({
required this.id,
required this.groupId,
required this.name,
required this.thumbnailUrl,
required this.location,
});
...
}
class UpdateProfileUseCase {
void execute(Profile profile) {}
}引数の検証としては主に 2 つ方法があります。
Recipe
argThat
argThat を使用することで Matcher を渡すことができます。
captureAny
captureAny によって引数を取得することができます。
Result
最終更新
役に立ちましたか?