Skip to content
This repository has been archived by the owner on Mar 18, 2021. It is now read-only.

Commit

Permalink
Fixed bug with isNotPresent in partial matcher. (#143)
Browse files Browse the repository at this point in the history
* Fixed bug with isNotPresent in partial matcher.

* Added a test, caught another bug, fixed the bug.

* Check success case.
  • Loading branch information
anachlas authored and itsjoeconway committed Dec 1, 2016
1 parent 0590b99 commit c907b5f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lib/src/utilities/test_matchers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -379,18 +379,17 @@ class _PartialMapMatcher extends Matcher {
for (var matchKey in map.keys) {
var matchValue = map[matchKey];
var value = item[matchKey];

if (value != null && matchValue is _NotPresentMatcher) {
var extra = matchState["extra"];
if (extra == null) {
extra = [];
matchState["extra"] = extra;
if (matchValue is _NotPresentMatcher) {
if (item.containsKey(matchKey)) {
var extra = matchState["extra"];
if (extra == null) {
extra = [];
matchState["extra"] = extra;
}
extra = matchKey;
return false;
}
extra = matchKey;
return false;
}

if (value == null) {
} else if (value == null && !matchValue.matches(value, matchState)) {
var missing = matchState["missing"];
if (missing == null) {
missing = [];
Expand Down
28 changes: 28 additions & 0 deletions test/utilities/test_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,34 @@ void main() {
expect(e.toString(), contains('Body: {"foo":"bar","x":5}'));
}
});

test("Partial match, null and not present", () async {
var defaultTestClient = new TestClient.onPort(4000);
server.queueResponse(new Response.ok({"foo": null, "bar" : "boo"}));
var response = await defaultTestClient.request("/foo").get();
expect(response, hasBody(partial({"bar": "boo"})));
expect(response, hasBody(partial({"foo": isNull})));
expect(response, hasBody(partial({"baz": isNotPresent})));

try {
expect(response, hasBody(partial({"foo": isNotPresent})));
expect(true, false);
} on TestFailure catch (e) {
expect(e.toString(),
contains("Expected: Body: Partially matches: {foo: <Instance of '_NotPresentMatcher'>,}"));
expect(e.toString(), contains('Body: {"foo":null,"bar":"boo"}'));
}
try {
expect(response, hasBody(partial({"bar": isNotPresent})));
expect(true, false);
} on TestFailure catch (e) {
expect(
e.toString(),
contains(
"Expected: Body: Partially matches: {bar: <Instance of '_NotPresentMatcher'>,}"));
expect(e.toString(), contains('Body: {"foo":null,"bar":"boo"}'));
}
});
});

group("Total matcher", () {
Expand Down

0 comments on commit c907b5f

Please sign in to comment.