Skip to content

Core selectors and modifiers

Chris Dibbern edited this page Apr 2, 2018 · 5 revisions

The FluentExpect API begins after an expect with a core set of selectors and modifiers. They are listed, here.

with

Begin talking about properties, e.g., .with.properties, .with.elements, etc. Passes along any negation.

without

A far-prettier alias for .not.with. You're welcome.

to

Begin talking about whole entities (as opposed to properties). E.g., .to.equal, .to.match, .to.satisfy, etc. Passes along any negation.

that

Synonymous with to. Available only when narrowing the scope is possible/meaningful.

Expect(val).to.have(p => p.prop).that.equals(3);

not

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 });

maybe

Facilitates parameterized testing (e.g., @TestCase).

Expect(lambda).maybe(ok).to.throw();

and

A no-op that helps grammatically beautify.

lastContextualValue

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;
Clone this wiki locally