Blame view

public/assets/addons/fastflow/plugins/node-qrcode-master/test/e2e/toFileStream.test.js 1.38 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
  const test = require('tap').test
  const sinon = require('sinon')
  const QRCode = require('lib')
  const StreamMock = require('../mocks/writable-stream')
  
  test('toFileStream png', function (t) {
    t.throw(function () { QRCode.toFileStream('some text') },
      'Should throw if stream is not provided')
  
    t.throw(function () { QRCode.toFileStream(new StreamMock()) },
      'Should throw if text is not provided')
  
    const fstream = new StreamMock()
    const spy = sinon.spy(fstream, 'emit')
  
    QRCode.toFileStream(fstream, 'i am a pony!')
  
    QRCode.toFileStream(fstream, 'i am a pony!', {
      type: 'image/png'
    })
  
    t.ok(spy.neverCalledWith('error'),
      'There should be no error')
  
    spy.restore()
    t.end()
  })
  
  test('toFileStream png with write error', function (t) {
    const fstreamErr = new StreamMock().forceErrorOnWrite()
    QRCode.toFileStream(fstreamErr, 'i am a pony!')
  
    t.plan(2)
  
    fstreamErr.on('error', function (e) {
      t.ok(e, 'Should return an error')
    })
  })
  
  test('toFileStream png with qrcode error', function (t) {
    const fstreamErr = new StreamMock()
    const bigString = Array(200).join('i am a pony!')
  
    t.plan(2)
  
    fstreamErr.on('error', function (e) {
      t.ok(e, 'Should return an error')
    })
  
    QRCode.toFileStream(fstreamErr, bigString)
    QRCode.toFileStream(fstreamErr, 'i am a pony!', {
      version: 1, // force version=1 to trigger an error
      errorCorrectionLevel: 'H'
    })
  })