mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-29 08:21:11 +00:00
31 lines
941 B
JavaScript
31 lines
941 B
JavaScript
'use strict'
|
|
|
|
var chai = require('chai')
|
|
|
|
global.expect = chai.expect
|
|
|
|
exports.expectError = function errorTypeExpectError (e, expected) {
|
|
// should set the name to the error's name
|
|
expect(e.name).to.equal(expected.name)
|
|
|
|
// should be an instance of the error type
|
|
expect(e instanceof expected.klass).to.be.true
|
|
|
|
// should be an instance of the built-in Error type
|
|
expect(e instanceof Error).to.be.true
|
|
|
|
// should be recognised by util.isError
|
|
expect(require('util').isError(e)).to.be.true
|
|
|
|
// should have a stack trace
|
|
expect(e.stack).to.be.truthy
|
|
|
|
// toString should return the default error message formatting
|
|
expect(e.toString()).to.equal(expected.message)
|
|
|
|
// stack should start with the default error message formatting
|
|
expect(e.stack.split('\n')[0], expected.name)
|
|
|
|
// first stack frame should be the function where the error was thrown
|
|
expect(e.stack.split('\n')[1]).to.match(expected.firstFrameRx)
|
|
}
|