From 6662fc31934565ef8ba6d693d117b099dcf148d0 Mon Sep 17 00:00:00 2001 From: Nirzara Ghure <113231114+nirzaraghure@users.noreply.github.com> Date: Sun, 12 Apr 2026 06:41:22 +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 | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 script.test.js diff --git a/script.test.js b/script.test.js new file mode 100644 index 0000000..7e845e8 --- /dev/null +++ b/script.test.js @@ -0,0 +1,36 @@ +const { JSDOM } = require('jsdom'); +const { expect } = require('@jest/globals'); +const script = require('./script.js'); + +describe('generateQR function', () => { + let dom; + let document; + let generateButton; + let textInput; + + beforeEach(() => { + dom = new JSDOM('
'); + document = dom.window.document; + generateButton = document.getElementById("generateButton"); + textInput = document.getElementById("text"); + }); + + afterEach(() => { + dom = null; + document = null; + generateButton = null; + textInput = null; + }); + + it('should throw an error for non-string input', () => { + textInput.value = 123; + generateButton.dispatchEvent(new dom.window.Event('click')); + expect(() => script.generateQR()).toThrowError('Input must be a string'); + }); + + it('should not throw an error for string input', () => { + textInput.value = 'test'; + generateButton.dispatchEvent(new dom.window.Event('click')); + expect(() => script.generateQR()).not.toThrowError(); + }); +}); \ No newline at end of file