Blame view

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