From 29ff6b7987d78e7e7f06fab22db88d3d3d34a0fb Mon Sep 17 00:00:00 2001 From: Nirzara Ghure <113231114+nirzaraghure@users.noreply.github.com> Date: Fri, 10 Apr 2026 10:11:40 +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 | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 script.test.js diff --git a/script.test.js b/script.test.js new file mode 100644 index 0000000..19012e5 --- /dev/null +++ b/script.test.js @@ -0,0 +1,47 @@ +import { JSDOM } from 'jsdom'; +import { expect } from 'chai'; +import script from './script.js'; + +const { document } = new JSDOM('').window; + +describe('generateQR function', () => { + beforeEach(() => { + document.body.innerHTML = ` + +
+ + `; + }); + + it('should show alert when inputElement.value is null', () => { + const inputElement = document.getElementById("text"); + inputElement.value = null; + const generateButton = document.getElementById("generateButton"); + generateButton.click(); + expect(document.querySelector('.alert')).to.not.be.null; + }); + + it('should show alert when inputElement.value is undefined', () => { + const inputElement = document.getElementById("text"); + inputElement.value = undefined; + const generateButton = document.getElementById("generateButton"); + generateButton.click(); + expect(document.querySelector('.alert')).to.not.be.null; + }); + + it('should show alert when inputElement.value is empty string', () => { + const inputElement = document.getElementById("text"); + inputElement.value = ""; + const generateButton = document.getElementById("generateButton"); + generateButton.click(); + expect(document.querySelector('.alert')).to.not.be.null; + }); + + it('should throw error when inputElement.value is not a string', () => { + const inputElement = document.getElementById("text"); + inputElement.value = 123; + const generateButton = document.getElementById("generateButton"); + generateButton.click(); + expect(window.console.error).to.have.been.called.with("Input must be a string"); + }); +}); \ No newline at end of file