-
Notifications
You must be signed in to change notification settings - Fork 27
Matchers: Core
drewbourne edited this page Sep 13, 2010
·
1 revision
allOf
matches if an item matches all of the given Matchers.
assertThat("good", allOf(equalTo("good"), not(equalTo("bad"))));
anyOf
matches if the item being matched matches any of the given Matchers.
assertThat("good", anyOf(equalTo("bad"), equalTo("good")));
anything
always matches.
assertThat("the great void", anything());
both
, and either
create a CombinableMatcher, useful for chaining matchers together for readability.
assertThat("good", both(equalTo("good")).and(not(equalTo("bad")); assertThat("good", either(equalTo("good")).or(not(equalTo("bad"));
describedAs
wraps another Matcher to return a modified description.
assertThat(3, describedAs("%0 is a magic number", equalTo(3), 3);
isA
matches if the item is an instance of the given type.
assertThat("waffles", isA(String));
not
inverts the result of another Matcher or value.
assertThat(3, not(4));
throws
matches if the item under test is a Function, and throws an Error matching the given Matcher.
assertThat(function():void { systemUnderTest.methodCall(given, bad, args); }, throws( allOf( instanceOf(OhNoItsAnError), hasPropertyValue("message", "oh no"))));