From 41143631bc55e0e32d6c47e05b3ec180664c81bd Mon Sep 17 00:00:00 2001 From: Nirzara Ghure <113231114+nirzaraghure@users.noreply.github.com> Date: Sun, 12 Apr 2026 07:12:51 +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 | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 script.test.js diff --git a/script.test.js b/script.test.js new file mode 100644 index 0000000..1f9207d --- /dev/null +++ b/script.test.js @@ -0,0 +1,46 @@ +describe('generateQR function', () => { + let inputElement; + let qrCodeDiv; + let generateButton; + let consoleSpy; + + beforeEach(() => { + document.body.innerHTML = ` + +
+ + `; + inputElement = document.getElementById("text"); + qrCodeDiv = document.getElementById("qrcode"); + generateButton = document.getElementById("generateButton"); + consoleSpy = jest.spyOn(console, 'error'); + }); + + afterEach(() => { + consoleSpy.mockRestore(); + }); + + it('should throw an error when input is null', () => { + inputElement.value = null; + expect(() => generateQR()).toThrowError('Input must be a string'); + expect(consoleSpy).not.toHaveBeenCalled(); + }); + + it('should throw an error when input is an empty string', () => { + inputElement.value = ""; + expect(() => generateQR()).toThrowError('Input must be a string'); + expect(consoleSpy).not.toHaveBeenCalled(); + }); + + it('should throw an error when input is an empty element', () => { + inputElement.value = ""; + expect(() => generateQR()).toThrowError('Input must be a string'); + expect(consoleSpy).not.toHaveBeenCalled(); + }); + + it('should handle input validation correctly', () => { + inputElement.value = "Hello, world!"; + generateButton.click(); + expect(consoleSpy).not.toHaveBeenCalled(); + }); +}); \ No newline at end of file