From 4624f6a51d4bf93e806e9ab09223989a2f6c032d Mon Sep 17 00:00:00 2001 From: Bartek Fabiszewski Date: Thu, 12 Dec 2019 16:36:35 +0100 Subject: [PATCH] Throw error on wrong argument type --- js/src/select.js | 3 +++ js/test/select.test.js | 6 ++++++ 2 files changed, 9 insertions(+) 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);