source: frontend/node_modules/bfj/test/unit/jsonstream.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[9af201e]1'use strict'
2
3const assert = require('chai').assert
4const spooks = require('spooks')
5
6const modulePath = '../../src/jsonstream'
7
8suite('jsonstream:', () => {
9 let log
10
11 setup(() => {
12 log = {}
13 })
14
15 test('require does not throw', () => {
16 assert.doesNotThrow(() => {
17 require(modulePath)
18 })
19 })
20
21 test('require returns function', () => {
22 assert.isFunction(require(modulePath))
23 })
24
25 suite('require:', () => {
26 let Stream
27
28 setup(() => {
29 Stream = require(modulePath)
30 })
31
32 test('Stream expects two arguments', () => {
33 assert.lengthOf(Stream, 2)
34 })
35
36 test('calling Stream with function argument doesNotThrow', () => {
37 assert.doesNotThrow(() => {
38 Stream(() => {})
39 })
40 })
41
42 test('calling Stream with object argument throws', () => {
43 assert.throws(() => {
44 Stream({ read: () => {} })
45 })
46 })
47
48 test('calling Stream with new returns Stream instance', () => {
49 assert.instanceOf(new Stream(() => {}), Stream)
50 })
51
52 test('calling Stream with new returns Readable instance', () => {
53 assert.instanceOf(new Stream(() => {}), require('stream').Readable)
54 })
55
56 test('calling Stream without new returns Stream instance', () => {
57 assert.instanceOf(Stream(() => {}), Stream)
58 })
59
60 suite('instantiate:', () => {
61 let jsonstream
62
63 setup(() => {
64 jsonstream = new Stream(spooks.fn({ name: 'read', log: log }))
65 })
66
67 test('jsonstream has _read method', () => {
68 assert.isFunction(jsonstream._read)
69 })
70
71 test('_read expects no arguments', () => {
72 assert.lengthOf(jsonstream._read, 0)
73 })
74
75 test('read was not called', () => {
76 assert.strictEqual(log.counts.read, 0)
77 })
78
79 suite('jsonstream._read:', () => {
80 setup(() => {
81 jsonstream._read()
82 })
83
84 test('read was called once', () => {
85 assert.strictEqual(log.counts.read, 1)
86 assert.isUndefined(log.these.read[0])
87 })
88
89 test('read was called correctly', () => {
90 assert.lengthOf(log.args.read[0], 0)
91 })
92 })
93 })
94 })
95})
Note: See TracBrowser for help on using the repository browser.