Remove ES5 interface

This commit is contained in:
John Lees-Miller
2019-07-08 11:52:59 +01:00
parent bdde7fac65
commit 96ab30883a
5 changed files with 1 additions and 163 deletions
-115
View File
@@ -1,115 +0,0 @@
'use strict'
var OError = require('..')
const { expectError } = require('./support')
describe('OError', function () {
it('defines a custom error type', function () {
var CustomError = OError.define('CustomError')
function doSomethingBad () {
throw new CustomError()
}
try {
doSomethingBad()
expect.fail('should have thrown')
} catch (e) {
expectError(e, {
name: 'CustomError',
klass: CustomError,
message: 'CustomError',
firstFrameRx: /doSomethingBad/
})
}
})
it('defines a custom error type with a message', function () {
var CustomError = OError.define('CustomError', function (x) {
this.message = 'x=' + x
this.x = x
})
function doSomethingBad () {
throw new CustomError('foo')
}
try {
doSomethingBad()
expect.fail('should have thrown')
} catch (e) {
expect(e.toString()).to.equal('CustomError: x=foo')
expect(e.message).to.equal('x=foo')
expect(e.x).to.equal('foo')
}
})
it('defines extended error type', function () {
var BaseError = OError.define('BaseError')
var DerivedError = OError.extend(BaseError, 'DerivedError')
function doSomethingBad () {
throw new DerivedError()
}
try {
doSomethingBad()
expect.fail('should have thrown')
} catch (e) {
expect(e.toString()).to.equal('DerivedError')
}
})
it('defines error types in a container object', function () {
var SomeClass = {}
OError.defineIn(SomeClass, 'CustomError')
function doSomethingBad () {
throw new SomeClass.CustomError()
}
try {
doSomethingBad()
expect.fail('should have thrown')
} catch (e) {
expect(e.toString()).to.equal('CustomError')
}
})
it('extends error types in a container object', function () {
var SomeClass = {}
OError.defineIn(SomeClass, 'CustomError', function (payload) {
this.message = 'custom error'
this.payload = payload
})
OError.extendIn(SomeClass, SomeClass.CustomError, 'DerivedCustomError',
function (payload) {
SomeClass.CustomError.call(this, payload)
this.message = 'derived custom error'
})
function doSomethingBad () {
throw new SomeClass.CustomError(123)
}
try {
doSomethingBad()
expect.fail('should have thrown')
} catch (e) {
expect(e.toString()).to.equal('CustomError: custom error')
expect(e.payload).to.equal(123)
}
function doSomethingBadWithDerived () {
throw new SomeClass.DerivedCustomError(456)
}
try {
doSomethingBadWithDerived()
expect.fail('should have thrown')
} catch (e) {
expect(e.toString()).to.equal('DerivedCustomError: derived custom error')
expect(e.payload).to.equal(456)
}
})
})
+1 -1
View File
@@ -4,7 +4,7 @@ var chai = require('chai')
global.expect = chai.expect
exports.expectError = function errorTypeExpectError (e, expected) {
exports.expectError = function OErrorExpectError (e, expected) {
// should set the name to the error's name
expect(e.name).to.equal(expected.name)