diff --git a/js/src/select.js b/js/src/select.js index a19479d..2eb6d6e 100644 --- a/js/src/select.js +++ b/js/src/select.js @@ -25,6 +25,9 @@ export default class uSelect { * @param {string=} all Optional all option text */ constructor(element, head, all) { + if (!(element instanceof HTMLSelectElement)) { + throw new Error('Invalid argument for select'); + } this.element = element; this.hasAllOption = false; this.allText = ''; diff --git a/js/test/select.test.js b/js/test/select.test.js index b15a729..1eaef56 100644 --- a/js/test/select.test.js +++ b/js/test/select.test.js @@ -57,6 +57,12 @@ describe('Select tests', () => { expect(select.headText).toBe(''); }); + it('should should throw error on wrong obligatory parameter type', () => { + // when + // then + expect(() => new uSelect(null)).toThrowError(/Invalid argument/); + }); + it('should construct class instance with header', () => { // when const select = new uSelect(element, head);