@dannybster/coco-the-bear-http-errors
Version:
A collection of error objects that represent http response objects for CoCo The Bear.
52 lines (42 loc) • 1.88 kB
JavaScript
const systemUnderTest = require('../src/404-not-found-error');
const VError = require('verror');
describe('404-not-found-error.js', function () {
describe('#createError', function () {
const info = {
description: 'Something arbitrary but highly useful!',
};
const msg = 'Resource was not found for some odd reason.';
const responseBody = {
something: 'Was not found.',
};
const error = systemUnderTest.createError(msg, info, responseBody);
it('it should create a VError object', function testCreatErrorObject() {
error.should.be.an.instanceOf(VError);
});
it('it should set the not found error object\'s message property to the value of the message parameter.', function testMessage() {
error.message.should.eql(msg);
});
it('it should set the not found error object\'s name to HTTP404NotFound.', function testCreateNotFoundErrorName() {
error.name.should.eql('HTTP404NotFound');
});
it('it should set the not found error object\'s info property to the value of the info parameter.', function testInfo() {
VError.info(error).should.eql(info);
});
it('it should set a response object on the error.', function testResponse() {
error.httpResponse.should.eql({
status: 404,
body: responseBody,
});
});
});
describe('#isNotFoundError', function () {
it('it should return false if called with an error that was not created with #createError', function testFalse() {
const error = new VError('Not a notFound error.');
systemUnderTest.isNotFoundError(error).should.eql(false);
});
it('it should return true if called with an error that was created with #createError', function testTrue() {
const error = systemUnderTest.createError('');
systemUnderTest.isNotFoundError(error).should.eql(true);
});
});
});