Assertion Libraries for Correctness Flashcards
What is an Assertion Library?
It’s a collection of assertions, typically many more than Node.js Assert, that supports comparisons of many different structures like objects, arrays, booleans, numbers, and more.
They provide an API, or in some cases, multiple APIs for developers to create predicates. The API provides interfaces in styles like TDD or BDD.
What does the ‘exists’ assertion do?
It checks whether something is neither null nor undefined.
What does the ‘typeOf’ assertion do?
It compares the object’s prototype.
What does the ‘instanceOf’ assertion do?
It determines whether an object is an instance of a particular constructor.
What does the ‘propertyByPath’ assertion do?
It checks a nested property by its path.
What does the ‘finally’ assertion do?
It checks that an object is a promise and will resolve to a specific value.
What is a chaining assertion?
It’s a special kind of assertion that in itself checks nothing. However, it passes values between assertions. This goes back to the natural language descriptions such as that of BDD.
What are some of the multiple aliases that chained assertions can have?
Chained assertions can have multiple aliases, all of which do the same thing. Terms like: be, an, of, a, and, been, have, has…
What is the benefit of assertion chaining?
It can improve readability and leads to a more natural-sounding description.
What are the top four assertion libraries that are available?
Assert – native, included in Node.js
Chai – chaijs.com
should.js – shouldjs.github.io
code – github.com/hapijs/code