mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-11 04:55:07 +00:00
update tests
This commit is contained in:
parent
9afd8e4e5d
commit
d63812c557
3 changed files with 21 additions and 46 deletions
libraries/o-error/test
|
@ -1,19 +1,19 @@
|
|||
const errorType = require('..')
|
||||
const OError = require('..')
|
||||
const { expectError } = require('./support')
|
||||
|
||||
class CustomError1 extends errorType.Error {
|
||||
class CustomError1 extends OError {
|
||||
constructor (options) {
|
||||
super({ message: 'failed to foo', ...options })
|
||||
}
|
||||
}
|
||||
|
||||
class CustomError2 extends errorType.Error {
|
||||
class CustomError2 extends OError {
|
||||
constructor (options) {
|
||||
super({ message: 'failed to bar', ...options })
|
||||
}
|
||||
}
|
||||
|
||||
describe('errorType.Error', () => {
|
||||
describe('OError', () => {
|
||||
it('handles a custom error type with a cause', () => {
|
||||
function doSomethingBadInternally () {
|
||||
throw new Error('internal error')
|
||||
|
@ -37,8 +37,8 @@ describe('errorType.Error', () => {
|
|||
message: 'CustomError1: failed to foo: internal error',
|
||||
firstFrameRx: /doSomethingBad/
|
||||
})
|
||||
expect(errorType.getFullInfo(e)).to.deep.equal({ userId: 123 })
|
||||
const fullStack = errorType.getFullStack(e)
|
||||
expect(OError.getFullInfo(e)).to.deep.equal({ userId: 123 })
|
||||
const fullStack = OError.getFullStack(e)
|
||||
expect(fullStack).to.match(
|
||||
/^CustomError1: failed to foo: internal error$/m
|
||||
)
|
||||
|
@ -79,11 +79,11 @@ describe('errorType.Error', () => {
|
|||
message: 'CustomError1: failed to foo: failed to bar: internal error',
|
||||
firstFrameRx: /doFoo/
|
||||
})
|
||||
expect(errorType.getFullInfo(e)).to.deep.equal({
|
||||
expect(OError.getFullInfo(e)).to.deep.equal({
|
||||
userId: 123,
|
||||
database: 'a'
|
||||
})
|
||||
const fullStack = errorType.getFullStack(e)
|
||||
const fullStack = OError.getFullStack(e)
|
||||
expect(fullStack).to.match(
|
||||
/^CustomError1: failed to foo: failed to bar: internal error$/m
|
||||
)
|
||||
|
@ -101,34 +101,9 @@ describe('errorType.Error', () => {
|
|||
throw new CustomError1({})
|
||||
expect.fail('should have thrown')
|
||||
} catch (e) {
|
||||
expect(errorType.getFullInfo(e)).to.deep.equal({})
|
||||
expect(OError.getFullInfo(e)).to.deep.equal({})
|
||||
let infoKey = Object.keys(e).find(k => k === 'info')
|
||||
expect(infoKey).to.not.exist
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('errorType.ErrorWithStatusCode', () => {
|
||||
it('accepts a status code', () => {
|
||||
function findPage () {
|
||||
throw new errorType.ErrorWithStatusCode({
|
||||
message: 'page not found',
|
||||
info: { url: '/foo' },
|
||||
statusCode: 404
|
||||
})
|
||||
}
|
||||
|
||||
try {
|
||||
findPage()
|
||||
} catch (e) {
|
||||
expectError(e, {
|
||||
name: 'ErrorWithStatusCode',
|
||||
klass: errorType.ErrorWithStatusCode,
|
||||
message: 'ErrorWithStatusCode: page not found',
|
||||
firstFrameRx: /findPage/
|
||||
})
|
||||
expect(e.statusCode).to.equal(404)
|
||||
expect(e.info).to.deep.equal({url: '/foo'})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const { getFullInfo, getFullStack, hasCauseInstanceOf } = require('..')
|
||||
|
||||
describe('errorType.getFullInfo', () => {
|
||||
describe('OError.getFullInfo', () => {
|
||||
it('works on a normal error', () => {
|
||||
const err = new Error('foo')
|
||||
expect(getFullInfo(err)).to.deep.equal({ })
|
||||
|
@ -43,7 +43,7 @@ describe('errorType.getFullInfo', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('errorType.getFullStack', () => {
|
||||
describe('OError.getFullStack', () => {
|
||||
it('works on a normal error', () => {
|
||||
const err = new Error('foo')
|
||||
const fullStack = getFullStack(err)
|
||||
|
@ -63,7 +63,7 @@ describe('errorType.getFullStack', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('errorType.hasCauseInstanceOf', () => {
|
||||
describe('OError.hasCauseInstanceOf', () => {
|
||||
it('works on a normal error', () => {
|
||||
const err = new Error('foo')
|
||||
expect(hasCauseInstanceOf(null, Error)).to.be.false
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
'use strict'
|
||||
|
||||
var errorType = require('..')
|
||||
var OError = require('..')
|
||||
const { expectError } = require('./support')
|
||||
|
||||
describe('errorType', function () {
|
||||
describe('OError', function () {
|
||||
it('defines a custom error type', function () {
|
||||
var CustomError = errorType.define('CustomError')
|
||||
var CustomError = OError.define('CustomError')
|
||||
|
||||
function doSomethingBad () {
|
||||
throw new CustomError()
|
||||
|
@ -25,7 +25,7 @@ describe('errorType', function () {
|
|||
})
|
||||
|
||||
it('defines a custom error type with a message', function () {
|
||||
var CustomError = errorType.define('CustomError', function (x) {
|
||||
var CustomError = OError.define('CustomError', function (x) {
|
||||
this.message = 'x=' + x
|
||||
this.x = x
|
||||
})
|
||||
|
@ -45,8 +45,8 @@ describe('errorType', function () {
|
|||
})
|
||||
|
||||
it('defines extended error type', function () {
|
||||
var BaseError = errorType.define('BaseError')
|
||||
var DerivedError = errorType.extend(BaseError, 'DerivedError')
|
||||
var BaseError = OError.define('BaseError')
|
||||
var DerivedError = OError.extend(BaseError, 'DerivedError')
|
||||
|
||||
function doSomethingBad () {
|
||||
throw new DerivedError()
|
||||
|
@ -62,7 +62,7 @@ describe('errorType', function () {
|
|||
|
||||
it('defines error types in a container object', function () {
|
||||
var SomeClass = {}
|
||||
errorType.defineIn(SomeClass, 'CustomError')
|
||||
OError.defineIn(SomeClass, 'CustomError')
|
||||
|
||||
function doSomethingBad () {
|
||||
throw new SomeClass.CustomError()
|
||||
|
@ -78,11 +78,11 @@ describe('errorType', function () {
|
|||
|
||||
it('extends error types in a container object', function () {
|
||||
var SomeClass = {}
|
||||
errorType.defineIn(SomeClass, 'CustomError', function (payload) {
|
||||
OError.defineIn(SomeClass, 'CustomError', function (payload) {
|
||||
this.message = 'custom error'
|
||||
this.payload = payload
|
||||
})
|
||||
errorType.extendIn(SomeClass, SomeClass.CustomError, 'DerivedCustomError',
|
||||
OError.extendIn(SomeClass, SomeClass.CustomError, 'DerivedCustomError',
|
||||
function (payload) {
|
||||
SomeClass.CustomError.call(this, payload)
|
||||
this.message = 'derived custom error'
|
||||
|
|
Loading…
Add table
Reference in a new issue