index.js 941 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict'
  2. var chai = require('chai')
  3. global.expect = chai.expect
  4. exports.expectError = function errorTypeExpectError (e, expected) {
  5. // should set the name to the error's name
  6. expect(e.name).to.equal(expected.name)
  7. // should be an instance of the error type
  8. expect(e instanceof expected.klass).to.be.true
  9. // should be an instance of the built-in Error type
  10. expect(e instanceof Error).to.be.true
  11. // should be recognised by util.isError
  12. expect(require('util').isError(e)).to.be.true
  13. // should have a stack trace
  14. expect(e.stack).to.be.truthy
  15. // toString should return the default error message formatting
  16. expect(e.toString()).to.equal(expected.message)
  17. // stack should start with the default error message formatting
  18. expect(e.stack.split('\n')[0], expected.name)
  19. // first stack frame should be the function where the error was thrown
  20. expect(e.stack.split('\n')[1]).to.match(expected.firstFrameRx)
  21. }