terminal.test.js
2.05 KB
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
const test = require('tap').test
const QRCode = require('core/qrcode')
const TerminalRenderer = require('renderer/terminal')
test('TerminalRenderer interface', function (t) {
t.type(TerminalRenderer.render, 'function',
'Should have render function')
t.end()
})
test('TerminalRenderer render big', function (t) {
const sampleQrData = QRCode.create('sample text', { version: 2 })
let str
t.notThrow(function () { str = TerminalRenderer.render(sampleQrData) },
'Should not throw with only qrData param')
t.notThrow(function () {
str = TerminalRenderer.render(sampleQrData, {
margin: 10,
scale: 1
})
}, 'Should not throw with options param')
t.type(str, 'string',
'Should return a string')
t.notThrow(function () {
str = TerminalRenderer.render(sampleQrData, { inverse: true })
}, 'Should not throw with inverse options')
t.type(str, 'string',
'Should return a string if inverse option is set')
t.end()
})
test('TerminalRenderer render small', function (t) {
const sampleQrData = QRCode.create('sample text', { version: 2 })
let str
let calledCallback = false
const callback = function () { calledCallback = true }
t.notThrow(function () { str = TerminalRenderer.render(sampleQrData) },
'Should not throw with only qrData param')
t.notThrow(function () {
str = TerminalRenderer.render(sampleQrData, {
margin: 10,
scale: 1,
small: true
})
}, 'Should not throw with options param and without callback')
t.notThrow(function () {
str = TerminalRenderer.render(sampleQrData, {
margin: 10,
scale: 1,
small: true
},
callback)
}, 'Should not throw with options param and callback')
t.type(str, 'string',
'Should return a string')
t.equal(calledCallback, true, 'string',
'Should call a callback')
t.notThrow(function () {
str = TerminalRenderer.render(sampleQrData, { small: true, inverse: true })
}, 'Should not throw with inverse options')
t.type(str, 'string',
'Should return a string if inverse option is set')
t.end()
})