【发布时间】:2021-08-25 13:04:56
【问题描述】:
我有一个检查异常的测试:
test('throws an exception if missing data', () async {
final client = MockClient();
final _apiService = ApiService(client, 'test/');
when(
client.post(
Uri.parse('test/user/auth_user'),
headers: {
'Content-Type': 'application/json',
},
body: json.encode({"email": '', "password": ''}),
),
).thenAnswer(
(_) async => http.Response(
'{"status": 400,"data": {"message": "Missing email or password fields"}}',
400,
),
);
expect(
await _apiService.login(email: '', password: ''),
isA<MissingDataException>(),
);
});
但不工作,这是测试的输出:
这是我的例外:
class MissingDataException implements Exception {
String message;
MissingDataException(this.message);
}
我试过了
throwsException
并没有工作。
我也试过
throwsA(TypeMatcher<MissingDataException>())
也没有工作。
我能做什么?
提前致谢。
【问题讨论】: