From 66a7bef054d0c226b1e9fe2595ebebf44c990686 Mon Sep 17 00:00:00 2001 From: Jonas Eckstein Date: Mon, 31 Jan 2022 18:29:26 +0100 Subject: [PATCH] Add test for binary data like in README.md --- test/e2e/toString.test.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/e2e/toString.test.js b/test/e2e/toString.test.js index f2b00dcf..2aea4d45 100644 --- a/test/e2e/toString.test.js +++ b/test/e2e/toString.test.js @@ -231,3 +231,31 @@ test('toString terminal', function (t) { t.equal(code + '\n', expectedTerminal, 'should output a valid symbol (promise)') }) }) + +test('toString byte-input', function (t) { + const expectedOutput = [ + ' ', + ' ', + ' █▀▀▀▀▀█ █▄█▀ █▀▀▀▀▀█ ', + ' █ ███ █ ▀█ █▀ █ ███ █ ', + ' █ ▀▀▀ █ ▀ █ █ ▀▀▀ █ ', + ' ▀▀▀▀▀▀▀ █▄▀▄█ ▀▀▀▀▀▀▀ ', + ' ▀██▄██▀▀▀█▀▀ ▀█ ▄▀▄ ', + ' ▀█▀▄█▄▀▄ ██ ▀ ▄ ▀▄ ▀ ', + ' ▀ ▀ ▀▀▀▀█▄ ▄▀▄▀▄▀▄▀▄▀ ', + ' █▀▀▀▀▀█ █ █▄█▀█▄█ ▀ ', + ' █ ███ █ ▀█▀▀ ▀██ ▀█▀ ', + ' █ ▀▀▀ █ ██▀ ▀ ▄ ▀▄▀▄▀ ', + ' ▀▀▀▀▀▀▀ ▀▀▀ ▀ ▀▀▀ ▀▀▀ ', + ' ', + ' ' + ].join('\n') + const byteInput = new Uint8ClampedArray([1, 2, 3, 4, 5]) + + t.plan(2) + + QRCode.toString([{ data: byteInput, mode: 'byte' }], { errorCorrectionLevel: 'L' }, (err, code) => { + t.ok(!err, 'there should be no error') + t.equal(code, expectedOutput, 'should output the correct code') + }) +})