-
Notifications
You must be signed in to change notification settings - Fork 0
Property assertions
The following methods analyze the components of an entity, rather than the entity as a whole. As with entity assertions, property assertions can be negated with not
and maybe
(see core selectors and modifiers).
Recursively asserts over the expected object's properties.
The following example demonstrates several ways of making these assertions.
Expect(viewModel).with.properties({
username: /exampleuser\d+/,
email: e => Expect(e).to.match(/\w+\@example.com/),
academicInfo: {
gpa: g => g > 3.5,
type: "Graduate Student"
}
});
Each property can be a:
- lambda returning a boolean pass/fail
- void lambda
- lambda using a complete FluentExpect sentence (as opposed to one with dangling core functions)
- regular expression
- value whose type is the same as the original property. In this case, a strict equals (===) will be performed.
- nested dictionary of property assertions for that (complex) value's properties
Like .with.properties
, except that it requires (at compile time) all properties to be specified, not only a subset. Failure to do so will result in compile-time errors. This helps ensure that your tests stay up-to-date with any model changes.
Verifies that the expected object contains the given keys, with no assumptions made about the corresponding values.
Expect(viewModel).with.keys(["one", "two", "three");
// .without is synonymous with .not.with
Expect(viewModel).without.keys(["four", "five", "six"]);
Verifies that the expected array contains the given elements.
Expect(results).with.elements([4,5,6]);
// .without is synonymous with .not.with
Expect(viewModel).without.elements([1,2,3]);