September 2018
Intermediate to advanced
764 pages
20h 6m
English
At the moment, if one of the assertions fails, we're throwing a generic Error object:
throw new Error();
When the test actually fails, the error message is not helpful because it doesn't tell us what the actual result is:
✗ Then our API should respond with a 400 HTTP status code {} Error at World.<anonymous>
We can improve this by throwing an instance of AssertionError instead of just an instance of Error. AssertionError is a class provided by Node.js that allows you to specify the expected and actual outcomes.
To use it, first import it from the assert module:
import { AssertionError } from 'assert';
Then, change our step definition to the following:
Then('our API should respond with a 400 HTTP status code', ...Read now
Unlock full access