2db47680
hexiaodong
chore: 初始提交 php 遗...
|
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
const test = require('tap').test
const { Canvas, createCanvas } = require('canvas')
const QRCode = require('lib')
const Helpers = require('test/helpers')
test('toCanvas - no promise available', function (t) {
Helpers.removeNativePromise()
// Mock document object
global.document = {
createElement: function (el) {
if (el === 'canvas') {
return createCanvas(200, 200)
}
}
}
const canvasEl = createCanvas(200, 200)
t.throw(function () { QRCode.toCanvas() },
'Should throw if no arguments are provided')
t.throw(function () { QRCode.toCanvas('some text') },
'Should throw if a callback is not provided')
t.throw(function () { QRCode.toCanvas(canvasEl, 'some text') },
'Should throw if a callback is not provided')
t.throw(function () { QRCode.toCanvas(canvasEl, 'some text', {}) },
'Should throw if callback is not a function')
t.end()
global.document = undefined
Helpers.restoreNativePromise()
})
test('toCanvas', function (t) {
// Mock document object
global.document = {
createElement: function (el) {
if (el === 'canvas') {
return createCanvas(200, 200)
}
}
}
t.plan(7)
t.throw(function () { QRCode.toCanvas() },
'Should throw if no arguments are provided')
QRCode.toCanvas('some text', function (err, canvasEl) {
t.ok(!err, 'There should be no error')
t.ok(canvasEl instanceof Canvas,
'Should return a new canvas object')
})
QRCode.toCanvas('some text', {
errorCorrectionLevel: 'H'
}, function (err, canvasEl) {
t.ok(!err, 'There should be no error')
t.ok(canvasEl instanceof Canvas,
'Should return a new canvas object')
})
QRCode.toCanvas('some text').then(function (canvasEl) {
t.ok(canvasEl instanceof Canvas,
'Should return a new canvas object (promise)')
})
QRCode.toCanvas('some text', {
errorCorrectionLevel: 'H'
}).then(function (canvasEl) {
t.ok(canvasEl instanceof Canvas,
'Should return a new canvas object (promise)')
})
global.document = undefined
})
test('toCanvas with specified canvas element', function (t) {
const canvasEl = createCanvas(200, 200)
t.plan(6)
QRCode.toCanvas(canvasEl, 'some text', function (err, canvasEl) {
t.ok(!err, 'There should be no error')
t.ok(canvasEl instanceof Canvas,
'Should return a new canvas object')
})
QRCode.toCanvas(canvasEl, 'some text', {
errorCorrectionLevel: 'H'
}, function (err, canvasEl) {
t.ok(!err, 'There should be no error')
t.ok(canvasEl instanceof Canvas,
'Should return a new canvas object')
})
QRCode.toCanvas(canvasEl, 'some text').then(function (canvasEl) {
t.ok(canvasEl instanceof Canvas,
'Should return a new canvas object (promise)')
})
QRCode.toCanvas(canvasEl, 'some text', {
errorCorrectionLevel: 'H'
}).then(function (canvasEl) {
t.ok(canvasEl instanceof Canvas,
'Should return a new canvas object (promise)')
})
})
|