src/test/helper/input.test.js   A
last analyzed

Complexity

Total Complexity 10
Complexity/F 1.11

Size

Lines of Code 47
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 10
c 1
b 0
f 0
nc 1
mnd 1
bc 11
fnc 9
dl 0
loc 47
rs 10
bpm 1.2222
cpm 1.1111
noi 4

1 Function

Rating   Name   Duplication   Size   Complexity  
B input.test.js ➔ ??? 0 45 1
1
const inputHelper = require('../../helper/input')
2
3
describe('Input helper', () => {
4
  const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
5
6
  it('input is a file path', () => {
7
    const mockCallback = jest.fn()
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
8
    inputHelper('src/test/sample.html', mockCallback)
9
    expect(mockCallback.mock.calls.length).toBe(1)
10
    expect(mockCallback.mock.calls[0][0]).toMatchSnapshot()
11
  })
12
13
  it('input is a not existed file path', () => {
14
    const mockCallback = jest.fn()
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
15
    inputHelper('src/test/dummy.html', mockCallback)
16
    expect(spy).toHaveBeenCalled()
17
    expect(mockCallback.mock.calls.length).toBe(0)
18
    expect(spy.mock.calls[0][0]).toContain('Cannot read file')
19
  })
20
21
  it('input is a read stream', done => {
22
    const Readable = require('stream').Readable
23
    const readable = new Readable()
24
    const mockCallback = jest.fn(() => {})
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
25
    readable._read = () => {}
26
    readable.push('streamData 1')
27
    readable.push('streamData 2')
28
    readable.push('streamData 3')
29
    inputHelper(readable, mockCallback)
30
    setTimeout(() => {
31
      try {
32
        expect(mockCallback.mock.calls[0][0]).toBe('streamData 1')
33
        expect(mockCallback.mock.calls[1][0]).toBe('streamData 2')
34
        expect(mockCallback.mock.calls[2][0]).toBe('streamData 3')
35
        done()
36
      } catch (err) {
37
        done.fail(err)
38
      }
39
    }, 2000)
40
  })
41
42
  it('input is invalid', () => {
43
    inputHelper(null)
44
    expect(spy).toHaveBeenCalled()
45
    expect(spy.mock.calls[1][0]).toContain('Invalid Input')
46
  })
47
})
48