Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkgs/matcher/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.12.21-wip

* Throw an `ArgumentError` when `isNot` or `anyOf` is used with an `AsyncMatcher`.

## 0.12.20

* Allow exceptions from `operator ==` to bubble up and fail the test instead of
Expand Down
12 changes: 11 additions & 1 deletion pkgs/matcher/lib/src/operator_matchers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'expect/async_matcher.dart';
import 'interfaces.dart';
import 'util.dart';

/// Returns a matcher that inverts [valueOrMatcher] to its logical negation.
Matcher isNot(Object? valueOrMatcher) => _IsNot(wrapMatcher(valueOrMatcher));
Matcher isNot(Object? valueOrMatcher) {
final matcher = wrapMatcher(valueOrMatcher);
if (matcher is AsyncMatcher) {
throw ArgumentError('isNot cannot be used with AsyncMatchers');
}
return _IsNot(matcher);
}

class _IsNot extends Matcher {
final Matcher _matcher;
Expand Down Expand Up @@ -108,6 +115,9 @@ class _AnyOf extends Matcher {
@override
bool matches(dynamic item, Map matchState) {
for (var matcher in _matchers) {
if (matcher is AsyncMatcher) {
throw ArgumentError('anyOf cannot be used with AsyncMatchers');
}
if (matcher.matches(item, matchState)) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/matcher/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: matcher
version: 0.12.20
version: 0.12.21-wip
description: >-
Support for specifying test expectations via an extensible Matcher class.
Also includes a number of built-in Matcher implementations for common cases.
Expand Down
4 changes: 0 additions & 4 deletions pkgs/matcher/test/expect_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,5 @@ void main() {
throwsA(isTestFailure(anything)),
);
});

test('can be used with synchronous operators', () {
expect(() {}, isNot(throwsA(anything)));
});
});
}
12 changes: 11 additions & 1 deletion pkgs/matcher/test/operator_matchers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:matcher/expect.dart' show expect, throwsA, throwsArgumentError;
import 'package:matcher/matcher.dart';
import 'package:test/test.dart' show expect, test, throwsArgumentError;
import 'package:test/test.dart' show test;

import 'test_utils.dart';

Expand Down Expand Up @@ -86,4 +87,13 @@ void main() {
throwsArgumentError,
);
});

test('isNot throws ArgumentError for AsyncMatcher', () {
expect(() => isNot(throwsA(anything)), throwsArgumentError);
});

test('anyOf throws ArgumentError for AsyncMatcher', () {
final matcher = anyOf(throwsA(anything));
expect(() => matcher.matches(null, {}), throwsArgumentError);
});
}
Loading