import * as jsdom from 'jsdom' import * as xjs from '../../index' import {ValueFunction} from '../../src/class/Element.class' import test from './test' let x: xjs.HTMLElement = new xjs.HTMLElement(jsdom.JSDOM.fragment('').querySelector('span') !) export default Promise.all([ test(x.outerHTML(), '') // set an attribute to a string .then(() => test(x.data('attrOne', 'val1').outerHTML(), '')) .then(() => test(x.data('attrOne') ! , 'val1')) // add a boolean attribute .then(() => test(x.data('attrTwo', '').outerHTML() , '')) .then(() => test(x.data('attrTwo') ! , '')) // remove an attribute .then(() => test(x.data('attrTwo', null).outerHTML() , '')) .then(() => test(`${x.data('attrTwo')}` , 'null')) // set an attribute to the string `'null'` .then(() => test(x.data('attrTwo', 'null').outerHTML(), '')) .then(() => test(x.data('attrTwo') ! , 'null')) // set an attribute using a function .then(() => test(x.data('attrThree', function () { return this.data('attrOne') }).outerHTML(), '')) .then(() => test((() => { let valueFn: ValueFunction = function (this: xjs.HTMLElement) { return this.data('attrTwo') } return x.data('attrThree', valueFn).outerHTML() })(), '')) // call `data()` with an object .then(() => test(x.data({ attrOne: 'string', attrTwo: 42, attrThree: true }).outerHTML(), '')) .then(() => test(x.data({ attrOne: null }).outerHTML() , '')) // call `data()` with no args, `null`, or an empty object `{}` .then(() => test(x.data( ).outerHTML() , '')) .then(() => test(x.data(null).outerHTML() , '')) .then(() => test(x.data({} ).outerHTML() , '')) // fail to call `data()` with `''` .then(() => test((() => { try { return x.data('') ! } catch (e) { return e.name } })(), 'RangeError')) // fail to call `data()` with `NaN` .then(() => test((() => { try { return x.data('foo', NaN).attr('foo') ! } catch (e) { return e.name } })(), 'NaNError')) ])