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