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 a property to a string .then(() => test(x.style('background', 'none').outerHTML() , '')) .then(() => test(x.style('background') ! , 'none')) .then(() => test(x.style('font-weight', 'bold').outerHTML(), '')) // remove a property using `''` .then(() => test(x.style('font-weight', '').outerHTML() , '')) .then(() => test(`${x.style('font-weight')}` , 'null')) // remove a property using `null` .then(() => test(x.style('background', null).outerHTML() , '')) .then(() => test(`${x.style('background')}` , 'null')) // set a property using a function .then(() => test(x.style('content', function () { return this.tagName }).outerHTML() , '')) .then(() => test(x.style('content', function () { return `'${this.tagName}'` }).outerHTML(), '')) .then(() => test((() => { let valueFn: ValueFunction = function (this: xjs.HTMLElement) { return null } return x.style('content', valueFn).outerHTML() })(), '')) // call `style()` with an object .then(() => test(x.style({ content: null, background: 'transparent', 'font-weight': 400, 'flex-wrap': true, }).outerHTML(), '')) // call `style()` with no args, `null`, or an empty object `{}` .then(() => test(x.style( ).outerHTML(), '')) .then(() => test(x.style(null).outerHTML(), '')) .then(() => test(x.attr({} ).outerHTML(), '')) // fail to call `style()` with `''` .then(() => test((() => { try { return x.style('') ! } catch (e) { return e.name } })(), 'RangeError')) // fail to call `style()` with `NaN` .then(() => test((() => { try { return x.style('order', NaN).style('order') ! } catch (e) { return e.name } })(), 'NaNError')) ])