neocotic / qrious

Pure JavaScript library for QR code generation using canvas

Home Page:https://neocotic.com/qrious

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error with unit test

dsumac opened this issue · comments

Hello,

I would like make unit tests and I have this error:

npm run test:ut -- QRCode

> hipigo@23.0.0 test:ut /opt/workspaces/hipigo
> jest -c jest.config.json --verbose "QRCode"

 FAIL  tests/ut/hippodrome/components/QRCode.test.jsx
  ● render › should render QRCode without any text

    TypeError: Cannot set property 'lineWidth' of null
      
      at constructor.reset (node_modules/qrious/dist/qrious.js:427:25)
      at constructor.render (node_modules/qrious/dist/qrious.js:355:14)
      at Object.update (node_modules/qrious/dist/qrious.js:2146:28)
      at new <anonymous> (node_modules/qrious/dist/qrious.js:2085:10)
      at _callee$ (tests/ut/hippodrome/components/QRCode.test.jsx:7:8)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:296:22)
      at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:114:21)
      at step (tests/ut/hippodrome/components/QRCode.test.jsx:3:357)
      at tests/ut/hippodrome/components/QRCode.test.jsx:3:587
          at new Promise (<anonymous>)
      at Object.<anonymous> (tests/ut/hippodrome/components/QRCode.test.jsx:3:268)
          at new Promise (<anonymous>)
      at Promise.resolve.then.el (node_modules/p-map/index.js:46:16)
          at <anonymous>

  render
    ✕ should render QRCode without any text (35ms)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        3.671s
Ran all test suites matching "QRCode".
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hipigo@23.0.0 test:ut: `jest -c jest.config.json --verbose "QRCode"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the hipigo@23.0.0 test:ut script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/d2i/.npm/_logs/2018-02-09T16_24_09_315Z-debug.log

The test code is very simple:

import { expect } from 'chai';
import QRious from 'qrious';

describe('render', () => {
	it('should render QRCode without any text', async () => {
		const qr = await new QRious({ value: 'test' });

		expect(qr.toDataUrl()).to.be.a('string');
	});
});

It seems there is a problem of testability.

I use mocha + chai to test.

Do you have any idea ?

Same issue with Jest

Sorry, actually my example was with jest