From b61361bba37a869cd3e84378713e26343729c9a7 Mon Sep 17 00:00:00 2001 From: Nirzara Ghure <113231114+nirzaraghure@users.noreply.github.com> Date: Sat, 11 Apr 2026 14:58:44 +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 | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 script.test.js diff --git a/script.test.js b/script.test.js new file mode 100644 index 0000000..52c77d1 --- /dev/null +++ b/script.test.js @@ -0,0 +1,39 @@ +import { JSDOM } from 'jsdom'; +import { expect } from 'expect'; +import { generateQR } from './script.js'; + +describe('generateQR function', () => { + let dom; + + beforeEach(() => { + dom = new JSDOM(` + + + + +
+ + + + + `); + globalThis.document = dom.window.document; + }); + + afterEach(() => { + globalThis.document = undefined; + }); + + it('should alert when input is empty', () => { + generateQR(); + const alertMessage = globalThis.alert; + expect(alertMessage).toBe('Please enter text or URL'); + }); + + it('should throw an error when input is not a string', () => { + const inputElement = globalThis.document.getElementById('text'); + inputElement.value = 123; + globalThis.document.getElementById('text').value = 123; + expect(() => generateQR()).toThrowError('Input must be a string'); + }); +}); \ No newline at end of file