Skip to content

Commit

Permalink
[update] update some error tips
Browse files Browse the repository at this point in the history
what:
why:
how:
  • Loading branch information
toxic-johann committed Aug 8, 2017
1 parent 347127a commit bd83f2e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions __tests__/dispatcher/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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();
});
});
8 changes: 4 additions & 4 deletions src/dispatcher/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
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];
}
/**
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit bd83f2e

Please sign in to comment.