Assertion Libraries for Correctness Flashcards

1
Q

What is an Assertion Library?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the ‘exists’ assertion do?

A

It checks whether something is neither null nor undefined.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the ‘typeOf’ assertion do?

A

It compares the object’s prototype.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the ‘instanceOf’ assertion do?

A

It determines whether an object is an instance of a particular constructor.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the ‘propertyByPath’ assertion do?

A

It checks a nested property by its path.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the ‘finally’ assertion do?

A

It checks that an object is a promise and will resolve to a specific value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a chaining assertion?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are some of the multiple aliases that chained assertions can have?

A

Chained assertions can have multiple aliases, all of which do the same thing. Terms like: be, an, of, a, and, been, have, has…

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the benefit of assertion chaining?

A

It can improve readability and leads to a more natural-sounding description.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the top four assertion libraries that are available?

A

Assert – native, included in Node.js
Chai – chaijs.com
should.js – shouldjs.github.io
code – github.com/hapijs/code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly