Skip to content

Commit

Permalink
Added some unit-tests for constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
dasilvacontin committed Aug 22, 2015
1 parent 063fc22 commit d96d9c2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/subclass-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ var SubclassError = require('../subclass-error')
describe('SubclassError', function () {
var ClientError = new SubclassError('ClientError', {statusCode: 400})
var ForbiddenError = new SubclassError('ForbiddenError', ClientError, {statusCode: 403})

describe('constructor', function () {
it('should throw when subclass name is not provided', function () {
(function () {
var unnamed = new SubclassError()
unnamed()
}).should.throw(/name.*first/i)
})

it('should throw when subclass name is not a string', function () {
(function () {
var invalidName = new SubclassError({})
invalidName()
}).should.throw(/expect.*string/i)
})
})

describe('instanceof', function () {
it('should work', function () {
var err = new ClientError()
Expand All @@ -17,17 +34,20 @@ describe('SubclassError', function () {
;(err instanceof Error).should.be.true
})
})

describe('properties', function () {
it('should be inherited in instances', function () {
(new ClientError()).statusCode.should.equal(400)
})

it('should be inherited in instances of a subclass', function () {
var FruitError = new SubclassError('FruitError', {type: 'food'})
var AppleError = new SubclassError('AppleError', FruitError)
var err = new AppleError()
err.type.should.equal('food')
})
})

describe('stack trace', function () {
it('should be correct', function () {
var NoFoodError = new SubclassError('NoFoodError')
Expand Down

0 comments on commit d96d9c2

Please sign in to comment.