react-qrcode-logo icon indicating copy to clipboard operation
react-qrcode-logo copied to clipboard

How can we test this component rendering?

Open bhushan-patil-official opened this issue 2 years ago • 1 comments

We are trying to write the tests for the component where we are using this. Although while running the test we are getting the error

The code we are writing to run the test is

describe("AuthQR component", () => {
	it("should render the component", () => {
		render(<AuthQR />);
	});
});

AuthQR is our component in which the QR Component using this library is being rendered. The code for the component goes like this

<QRCode
	value="something"
	size={250}
	ecLevel="L"
	bgColor="#FFFFFF"
	fgColor="#212636"
	id="aut-qr-code"
/>

While running the test We are encountering the error as follows

Cannot read properties of null (reading 'scale')
TypeError: Cannot read properties of null (reading 'scale')
    at QRCode.Object.<anonymous>.QRCode.update (/Users/bhushan/Documents/my-web/apps/web/node_modules/react-qrcode-logo/dist/index.js:162:13)
    at QRCode.Object.<anonymous>.QRCode.componentDidMount (/Users/bhushan/Documents/my-web/apps/web/node_modules/react-qrcode-logo/dist/index.js:145:14)
    at commitLayoutEffectOnFiber (/Users/bhushan/Documents/my-web/apps/web/node_modules/react-dom/cjs/react-dom.development.js:23310:28)

Can you please tell me what I am doing wrong?

bhushan-patil-official avatar Aug 17 '22 10:08 bhushan-patil-official

Jest doesn't support canvas natively, maybe try this SO solution?

omarryhan avatar Oct 13 '22 02:10 omarryhan