Blame view

public/assets/addons/fastflow/plugins/node-qrcode-master/test/unit/renderer/utf8.test.js 1.72 KB
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
  const test = require('tap').test
  const sinon = require('sinon')
  const fs = require('fs')
  const QRCode = require('core/qrcode')
  const Utf8Renderer = require('renderer/utf8')
  
  test('Utf8Renderer interface', function (t) {
    t.type(Utf8Renderer.render, 'function',
      'Should have render function')
  
    t.end()
  })
  
  test('Utf8Renderer render', function (t) {
    const sampleQrData = QRCode.create('sample text', { version: 2 })
    let str
  
    t.notThrow(function () { str = Utf8Renderer.render(sampleQrData) },
      'Should not throw with only qrData param')
  
    t.notThrow(function () {
      str = Utf8Renderer.render(sampleQrData, {
        margin: 10,
        scale: 1
      })
    }, 'Should not throw with options param')
  
    t.type(str, 'string',
      'Should return a string')
  
    t.end()
  })
  
  test('Utf8 renderToFile', function (t) {
    const sampleQrData = QRCode.create('sample text', { version: 2 })
    const fileName = 'qrimage.txt'
    let fsStub = sinon.stub(fs, 'writeFile').callsArg(2)
  
    t.plan(5)
  
    Utf8Renderer.renderToFile(fileName, sampleQrData, function (err) {
      t.ok(!err,
        'Should not generate errors with only qrData param')
  
      t.equal(fsStub.getCall(0).args[0], fileName,
        'Should save file with correct file name')
    })
  
    Utf8Renderer.renderToFile(fileName, sampleQrData, {
      margin: 10,
      scale: 1
    }, function (err) {
      t.ok(!err,
        'Should not generate errors with options param')
  
      t.equal(fsStub.getCall(0).args[0], fileName,
        'Should save file with correct file name')
    })
  
    fsStub.restore()
    fsStub = sinon.stub(fs, 'writeFile').callsArgWith(2, new Error())
  
    Utf8Renderer.renderToFile(fileName, sampleQrData, function (err) {
      t.ok(err,
        'Should fail if error occurs during save')
    })
  
    fsStub.restore()
  })