forked from alsatian-test/alsatian
-
Notifications
You must be signed in to change notification settings - Fork 0
Fluent API overview
Chris Dibbern edited this page Apr 7, 2018
·
4 revisions
The FluentExpect API provides a way to string assertions together with the possibility of narrowing the scope, when it makes sense, allowing you to communicate expectations clearly and concisely.
Here is an example of assertions that narrow scopes:
Expect(viewModel)
.to.have(v => v.someProp) // existence check + scope narrow
.that.isInstanceOf(MyModel) // type check
.and.that.has(p => p.itsOwnProp) // existence check + deepen scope
.that.equals(3);
Note that, at the fluent level, scopes can only narrow. To fork a scope, there are a few options. First, you can break it apart by assigning it to a variable:
let expectSomeProp = Expect(viewModel).to.have(v => v.someProp);
expectSomeProp.that.has(p => p.itsOwnProp);
expectSomeProp.that.has(p => p.someOther).that.equals(3);
Or, you can use properties matchers:
Expect(viewModel)
.with.properties({
someProp: p => Expect(p).to.beDefined(),
someOther: 3,
});