diff --git a/__tests__/dispatcher/dom.js b/__tests__/dispatcher/dom.js index 2fb9adb5..1f650245 100644 --- a/__tests__/dispatcher/dom.js +++ b/__tests__/dispatcher/dom.js @@ -2,7 +2,7 @@ import Dom from 'dispatcher/dom'; import {Log} from 'chimee-helper'; describe('dispatcher/dom', () => { test('dom needs wrapper and dispatcher if you pass in illegal desipatcher, it should throw error', () => { - expect(() => new Dom()).toThrow('Illegal wrapper'); + expect(() => new Dom()).toThrow('Wrapper can only be string or HTMLElement, but not undefined'); expect(() => new Dom('hello')).toThrow('Can not get dom node accroding wrapper. Please check your wrapper'); }); describe('wrapper can be string, indicate elment in document', () => { @@ -221,7 +221,7 @@ describe('_getEventHanlder', () => { expect(dom.container.style.zIndex).toBe('10'); expect(() => dom.setStyle('WHAT')).toThrow("to handle dom's attribute or style, your attr parameter must be string"); expect(() => dom.setStyle(1, 'hahahah')).toThrow("to handle dom's attribute or style, your target parameter must be string"); - expect(() => dom.setStyle('what', 'z-index')).toThrow('Your target what is not a legal HTMLElement'); + expect(() => dom.setStyle('what', 'z-index')).toThrow('Your target "what" is not a legal HTMLElement'); dom.destroy(); }); }); diff --git a/src/dispatcher/dom.js b/src/dispatcher/dom.js index 0f7a8c81..d1895c5a 100644 --- a/src/dispatcher/dom.js +++ b/src/dispatcher/dom.js @@ -4,12 +4,12 @@ import {videoEvents, domEvents} from 'helper/const'; import {autobind, before, waituntil} from 'toxic-decorators'; function targetCheck (target: string, ...args) { if(target === 'video') target = 'videoElement'; - if(!isElement(this[target])) throw new TypeError('Your target ' + target + ' is not a legal HTMLElement'); + if(!isElement(this[target])) throw new TypeError(`Your target "${target}" is not a legal HTMLElement`); return [target, ...args]; } function attrOperationCheck (target: string, attr: string, val: any): Array { - if(!isString(attr)) throw new TypeError("to handle dom's attribute or style, your attr parameter must be string"); - if(!isString(target)) throw new TypeError("to handle dom's attribute or style, your target parameter must be string"); + if(!isString(attr)) throw new TypeError(`to handle dom's attribute or style, your attr parameter must be string, but not ${attr} in ${typeof attr}`); + if(!isString(target)) throw new TypeError(`to handle dom's attribute or style, your target parameter must be string, , but not ${target} in ${typeof target}`); return [target, attr, val]; } /** @@ -86,7 +86,7 @@ export default class Dom { fullScreenElement = undefined; constructor (wrapper: string | Element, dispatcher: Dispatcher) { this.__dispatcher = dispatcher; - if(!isElement(wrapper) && !isString(wrapper)) throw new TypeError('Illegal wrapper'); + if(!isElement(wrapper) && !isString(wrapper)) throw new TypeError(`Wrapper can only be string or HTMLElement, but not ${typeof wrapper}`); const $wrapper = $(wrapper); if($wrapper.length === 0) { throw new TypeError('Can not get dom node accroding wrapper. Please check your wrapper');