chai-lodash
Fuzzy matchers for chai based on lodash and inspired by chai-fuzzy.
Make assertions that values have all the same attributes and values without asserting strict object equality.
Using
Also see the tests and examples.
browser-side
include chai lodash after chai and lodash:
server-side
have chai use chai-lodash:
var chai = ; chai;
Assertions
like(value)
compare object attributes and values rather than checking to see if they're the same reference
var subject = a: 'a'; subjectshouldbe; subjectshouldnotbe; subjectshouldnotbe; tobe; nottobe; nottobe; assert; assert; assert; var subject = 'a'; subjectshouldbe; subjectshouldnotbe; subjectshouldnotbe; tobe; nottobe; nottobe; assert; assert; assert;
containOneLike(value)
check the first level of the container for a value like the one provided
var subject = a: 'alphabet' b: 'butternut' c: name: 'chowder' attributes: 'scales' 'fins' x: 'xylophone' z: 'xylophone' ; subjectshould; subjectshouldnot; subjectshould; subjectshouldnot; to; tonot; assert; assert; // same for arrays
jsonOf(value)
check that the given javascript object is like the JSON-ified expected value. Useful for checking stringification and parsing of an object.
var apple = skin: 'thin' colors: 'red' 'green' 'yellow' isFruit: true picked: ; var orange = skin: 'thin' colors: 'red' 'green' 'yellow' isFruit: true picked: ; // here appleJSON would be the json result of some process like a JSON api var appleJSON = JSON; appleJSONshouldbe; appleJSONshouldnotbe; tobe; tonotbe; assert; assert;
Thanks
Thanks to Elliotf for contributing the very excellent Chai-Fuzzy, on which this is based.