Unit testing ValidationError
Next, let's focus on testing the ValidationError
class. Once again, we will move the validation.js
file into its own director:
$ cd src/validators/errors/ && \ mkdir validation-error && \ mv validation-error.js validation-error/index.js && \ cd ../../../
Now, create a new file atsrc/validators/errors/validation-error/index.unit.test.js
 to house our unit tests:
import assert from 'assert'; import ValidationError from '.'; describe('ValidationError', function () { it('should be a subclass of Error', function () { const validationError = new ValidationError(); assert.equal(validationError instanceof Error, true); }); describe('constructor', function () { it('should make the constructor parameter accessible via the `message` property of the instance', function () { const TEST_ERROR = 'TEST_ERROR'; const validationError = new ValidationError(TEST_ERROR); assert.equal(validationError.message, TEST_ERROR...