Throw error on wrong argument type

This commit is contained in:
Bartek Fabiszewski 2019-12-12 16:36:35 +01:00
parent 8f582892cd
commit 4624f6a51d
2 changed files with 9 additions and 0 deletions

View File

@ -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 = '';

View File

@ -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);