error.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. 'use strict'
  2. const assert = require('chai').assert
  3. const modulePath = '../../src/error'
  4. suite('error:', () => {
  5. let log
  6. setup(() => {
  7. log = {}
  8. })
  9. test('require does not throw', () => {
  10. assert.doesNotThrow(() => {
  11. require(modulePath)
  12. })
  13. })
  14. test('require returns object', () => {
  15. assert.isObject(require(modulePath))
  16. })
  17. suite('require:', () => {
  18. let error
  19. setup(() => {
  20. error = require(modulePath)
  21. })
  22. test('error has create method', () => {
  23. assert.isFunction(error.create)
  24. })
  25. test('error has no other methods', () => {
  26. assert.lengthOf(Object.keys(error), 1)
  27. })
  28. test('create expects four arguments', () => {
  29. assert.lengthOf(error.create, 4)
  30. })
  31. test('create does not throw', () => {
  32. assert.doesNotThrow(() => {
  33. error.create()
  34. })
  35. })
  36. test('create returns Error', () => {
  37. assert.instanceOf(error.create(), Error)
  38. })
  39. suite('create:', () => {
  40. let created
  41. setup(() => {
  42. created = error.create('foo', 'bar', 'baz', 'qux')
  43. })
  44. test('created has correct actual property', () => {
  45. assert.strictEqual(created.actual, 'foo')
  46. })
  47. test('created has correct expected property', () => {
  48. assert.strictEqual(created.expected, 'bar')
  49. })
  50. test('created has correct lineNumber property', () => {
  51. assert.strictEqual(created.lineNumber, 'baz')
  52. })
  53. test('created has correct columnNumber property', () => {
  54. assert.strictEqual(created.columnNumber, 'qux')
  55. })
  56. test('created has correct message property', () => {
  57. assert.strictEqual(created.message, 'JSON error: encountered `foo` at line baz, column qux where `bar` was expected.')
  58. })
  59. })
  60. })
  61. })