Bupkis comes with a smorgasbord of built-in assertions. Here's some general information about assertions.
Assertions or expectations have three (3) components when called via expect()/expectAsync().
See also: Subject (glossary)
The first argument to expect() is called the subject. The subject is the value being tested. For example, in expect(42, 'to be', 42)
, the subject is 42
.
See also: Phrase (glossary)
You may see the term phrase referenced in the documentation. A phrase is a string parameter to the expect() function that decides which assertion to execute. For example, in expect(42, 'to be', 42)
, the phrase is 'to be'
.
Assertions may have multiple phrases that end up executing the same assertion. We call these aliases. For example, the phrases 'to be'
, 'to equal'
, and 'is'
all execute the same equality assertion.
An assertion has at least one phrase, but may have more than one. For example, the following assertion has two phrases:
expect(
() => throw new TypeError('Oh no!'),
'to throw a',
TypeError,
'satisfying',
/Oh no/,
);
See also: Parameter (glossary)
A parameter is considered anything else that's neither a phrase nor a value. This comes into play when an assertion is parametric; this means the assertion expects some extra value to use in some manner.
Typically, a parameter is used for some type of comparison operation, but this is not a requirement.
You will see assertions accepting parameters referred to as parametric assertions.
Assertions without parameters are often called non-parametric assertions or just basic assertions.
Don't confuse parameters and phrases! Just because a
string
is expected does not mean that it is a phrase. For example, in the assertion:expect('bruh', 'to be a', 'string');
…the phrase is
'to be a'
and the parameter is'string'
.
Any assertion can be negated by prepending the first phrase with not
. For example:
expect(42, 'to be', 42);
// negated
expect(42, 'not to be', 42); // AssertionError; 42 is 42