Dart VM version: 2.0.0 (Fri Aug 3 10:53:23 2018 +0200) on “macos_x64”
MacOSX
// my_class.dart
class MyClass {
MyClass(String argument): assert(argument != null);
}
// my_class_test.dart
void main() {
group('constructor', () {
test('should throw when initialized with null argument', () {
expect(MyClass(null), throwsA(AssertionError));
});
});
}
Expected: Test Passes
Actual:
'my_class.dart': Failed assertion: line 8 pos 16: 'argument != null': is not true.
dart:core _AssertionError._throwNew
my_class.dart 8:16 new MyClass
unit_tests/my_class_test.dart 7:14 main.<fn>.<fn>
you should do something like
expect(() => MyClass(null), throwsA(...))
otherwise you throw outside ofexpect
.