From 5cf1d5d2cbc004f156cce586199ced58005d1f7e Mon Sep 17 00:00:00 2001 From: Nirzara Ghure <113231114+nirzaraghure@users.noreply.github.com> Date: Sun, 12 Apr 2026 06:26:32 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20AppGenius:=20AI-generated=20code?= =?UTF-8?q?=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script.test.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 script.test.js diff --git a/script.test.js b/script.test.js new file mode 100644 index 0000000..09de001 --- /dev/null +++ b/script.test.js @@ -0,0 +1,53 @@ +// Import required libraries +const { JSDOM } = require('jsdom'); +const { expect } = require('chai'); +const QRCode = require('qrcode'); + +// Create a mock DOM environment +const dom = new JSDOM(` + +
+ + + + + +`); + +// Mock DOM functions +global.document = dom.window.document; +global.window = dom.window; + +// Import the function to be tested +const generateQR = require('./script'); + +describe('generateQR function', () => { + it('throws an error for non-string input', () => { + const inputElement = document.getElementById('text'); + inputElement.value = '123'; + expect(() => generateQR()).to.throw('Input must be a string'); + }); + + it('does not throw an error for string input', () => { + const inputElement = document.getElementById('text'); + inputElement.value = 'Hello World'; + expect(() => generateQR()).not.to.throw(); + }); + + it('does not throw an error when input is trimmed', () => { + const inputElement = document.getElementById('text'); + inputElement.value = ' Hello World '; + generateQR(); + expect(() => generateQR()).not.to.throw(); + }); + + it('calls console.error when an error occurs during QR code generation', () => { + const consoleSpy = require('sinon').createStub().named('console.error'); + const inputElement = document.getElementById('text'); + inputElement.value = 'Hello World'; + const qrcodeDiv = document.getElementById('qrcode'); + qrcodeDiv.style.display = 'none'; + expect(() => generateQR()).to.throw(); + expect(consoleSpy.called).to.be.true; + }); +}); \ No newline at end of file