Blame view

node_modules/bfj-node4/test/unit/jsonstream.js 2.11 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  'use strict'
  
  const assert = require('chai').assert
  const spooks = require('spooks')
  
  const modulePath = '../../src/jsonstream'
  
  suite('jsonstream:', () => {
    let log
  
    setup(() => {
      log = {}
    })
  
    test('require does not throw', () => {
      assert.doesNotThrow(() => {
        require(modulePath)
      })
    })
  
    test('require returns function', () => {
      assert.isFunction(require(modulePath))
    })
  
    suite('require:', () => {
      let Stream
  
      setup(() => {
        Stream = require(modulePath)
      })
  
      test('Stream expects one argument', () => {
        assert.lengthOf(Stream, 1)
      })
  
      test('calling Stream with function argument doesNotThrow', () => {
        assert.doesNotThrow(() => {
          Stream(() => {})
        })
      })
  
      test('calling Stream with object argument throws', () => {
        assert.throws(() => {
          Stream({ read: () => {} })
        })
      })
  
      test('calling Stream with new returns Stream instance', () => {
        assert.instanceOf(new Stream(() => {}), Stream)
      })
  
      test('calling Stream with new returns Readable instance', () => {
        assert.instanceOf(new Stream(() => {}), require('stream').Readable)
      })
  
      test('calling Stream without new returns Stream instance', () => {
        assert.instanceOf(Stream(() => {}), Stream)
      })
  
      suite('instantiate:', () => {
        let jsonstream
  
        setup(() => {
          jsonstream = new Stream(spooks.fn({ name: 'read', log: log }))
        })
  
        test('jsonstream has _read method', () => {
          assert.isFunction(jsonstream._read)
        })
  
        test('_read expects no arguments', () => {
          assert.lengthOf(jsonstream._read, 0)
        })
  
        test('read was not called', () => {
          assert.strictEqual(log.counts.read, 0)
        })
  
        suite('jsonstream._read:', () => {
          setup(() => {
            jsonstream._read()
          })
  
          test('read was called once', () => {
            assert.strictEqual(log.counts.read, 1)
            assert.isUndefined(log.these.read[0])
          })
  
          test('read was called correctly', () => {
            assert.lengthOf(log.args.read[0], 0)
          })
        })
      })
    })
  })