-
Notifications
You must be signed in to change notification settings - Fork 0
Core selectors and modifiers
The FluentExpect API begins after an expect with a core set of selectors and modifiers. They are listed, here.
Begin talking about properties, e.g., .with.properties
, .with.elements
, etc. Passes along any negation.
A far-prettier alias for .not.with
. You're welcome.
Begin talking about whole entities (as opposed to properties). E.g., .to.equal
, .to.match
, .to.satisfy
, etc. Passes along any negation.
Synonymous with to. Available only when narrowing the scope is possible/meaningful.
Expect(val).to.have(p => p.prop).that.equals(3);
Negates subsequent context, e.g., Expect(val).not.to.equal(3)
.
Note: Negation only applies to the next term. For example:
Expect(lambda).not.to.throw(MyError).with.properties({ message: msg });
It might be tempting to believe this assertion will pass as long as any errors thrown don't have a message
equal to msg
. However, .not.to.throw
will fail before .with.properties
has a chance to execute. The proper
way to write this is:
Expect(lambda).to.throw(MyError).without.properties({ message: msg });
Facilitates parameterized testing (e.g., @TestCase
).
Expect(lambda).maybe(ok).to.throw();
A no-op that helps grammatically beautify.
Unwraps the contextual value from the Expect framework, and returns it. Useful mainly for debugging.
let propVal = Expect(val).to.have(p => p.prop).lastContextualValue;