Flutter: Test that a specific exception is thrown

后端 未结 4 517
攒了一身酷
攒了一身酷 2021-01-07 23:07

in short, throwsA(anything) does not suffice for me while unit testing in dart. How to I test for a specific error message or type?

Her

4条回答
  •  [愿得一人]
    2021-01-07 23:53

    First import correct package 'package:matcher/matcher.dart';

    expect(() => yourOperation.yourMethod(),
          throwsA(const TypeMatcher()));
    

提交回复
热议问题