test
test copied to clipboard
Add `throwsTypeError` to `throws_matchers.dart`
In my flutter tests, I am wanting to be able to assert that a TypeError was thrown. To do this, I have to do something like:
test('fromJson throws TypeError when "key" is of type Map instead of String', () {
expect(
() => Object.fromJson({
'key': {},
}),
throwsA(isA<TypeError>()),
);
});
The above test should also be able to be written as so:
test('fromJson throws TypeError when "key" is of type Map instead of String', () {
expect(
() => Object.fromJson({
'key': {},
}),
throwsTypeError),
);
});
Similar matchers are already supported, as seen here.