Throw error on wrong argument type
This commit is contained in:
parent
8f582892cd
commit
4624f6a51d
@ -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 = '';
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user