123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669 |
- 'use strict';
- var cssstyle = require('../lib/CSSStyleDeclaration');
- var { dashedToCamelCase } = require('../lib/parsers');
- var dashedProperties = [
- ...require('../lib/allProperties'),
- ...require('../lib/allExtraProperties'),
- ];
- var allowedProperties = dashedProperties.map(dashedToCamelCase);
- var implementedProperties = Array.from(require('../lib/implementedProperties')).map(
- dashedToCamelCase
- );
- var invalidProperties = implementedProperties.filter(function(property) {
- return !allowedProperties.includes(property);
- });
- module.exports = {
- 'Verify Has Only Valid Properties Implemented': function(test) {
- test.expect(1);
- test.ok(
- invalidProperties.length === 0,
- invalidProperties.length +
- ' invalid properties implemented: ' +
- Array.from(invalidProperties).join(', ')
- );
- test.done();
- },
- 'Verify Has All Properties': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(allowedProperties.length * 2);
- allowedProperties.forEach(function(property) {
- test.ok(style.__lookupGetter__(property), 'missing ' + property + ' property');
- test.ok(style.__lookupSetter__(property), 'missing ' + property + ' property');
- });
- test.done();
- },
- 'Verify Has All Dashed Properties': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(dashedProperties.length * 2);
- dashedProperties.forEach(function(property) {
- test.ok(style.__lookupGetter__(property), 'missing ' + property + ' property');
- test.ok(style.__lookupSetter__(property), 'missing ' + property + ' property');
- });
- test.done();
- },
- 'Verify Has Functions': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(6);
- test.ok(typeof style.getPropertyValue === 'function', 'missing getPropertyValue()');
- test.ok(typeof style.getPropertyCSSValue === 'function', 'missing getPropertyCSSValue()');
- test.ok(typeof style.removeProperty === 'function', 'missing removeProperty()');
- test.ok(typeof style.getPropertyPriority === 'function', 'missing getPropertyPriority()');
- test.ok(typeof style.setProperty === 'function', 'missing setProperty()');
- test.ok(typeof style.item === 'function', 'missing item()');
- test.done();
- },
- 'Verify Has Special Properties': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(5);
- test.ok(style.__lookupGetter__('cssText'), 'missing cssText getter');
- test.ok(style.__lookupSetter__('cssText'), 'missing cssText setter');
- test.ok(style.__lookupGetter__('length'), 'missing length getter');
- test.ok(style.__lookupSetter__('length'), 'missing length setter');
- test.ok(style.__lookupGetter__('parentRule'), 'missing parentRule getter');
- test.done();
- },
- 'Test From Style String': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(8);
- style.cssText = 'color: blue; background-color: red; width: 78%; height: 50vh;';
- test.ok(4 === style.length, 'length is not 4');
- test.ok(
- 'color: blue; background-color: red; width: 78%; height: 50vh;' === style.cssText,
- 'cssText is wrong'
- );
- test.ok('blue' === style.getPropertyValue('color'), "getPropertyValue('color') failed");
- test.ok('color' === style.item(0), 'item(0) failed');
- test.ok('background-color' === style[1], 'style[1] failed');
- test.ok(
- 'red' === style.backgroundColor,
- 'style.backgroundColor failed with "' + style.backgroundColor + '"'
- );
- style.cssText = '';
- test.ok('' === style.cssText, 'cssText is not empty');
- test.ok(0 === style.length, 'length is not 0');
- test.done();
- },
- 'Test From Properties': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(11);
- style.color = 'blue';
- test.ok(1 === style.length, 'length is not 1');
- test.ok('color' === style[0], 'style[0] is not color');
- test.ok('color: blue;' === style.cssText, 'cssText is wrong');
- test.ok('color' === style.item(0), 'item(0) is not color');
- test.ok('blue' === style.color, 'color is not blue');
- style.backgroundColor = 'red';
- test.ok(2 === style.length, 'length is not 2');
- test.ok('color' === style[0], 'style[0] is not color');
- test.ok('background-color' === style[1], 'style[1] is not background-color');
- test.ok('color: blue; background-color: red;' === style.cssText, 'cssText is wrong');
- test.ok('red' === style.backgroundColor, 'backgroundColor is not red');
- style.removeProperty('color');
- test.ok('background-color' === style[0], 'style[0] is not background-color');
- test.done();
- },
- 'Test Shorthand Properties': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(11);
- style.background = 'blue url(http://www.example.com/some_img.jpg)';
- test.ok('blue' === style.backgroundColor, 'backgroundColor is not blue');
- test.ok(
- 'url(http://www.example.com/some_img.jpg)' === style.backgroundImage,
- 'backgroundImage is wrong'
- );
- test.ok(
- 'blue url(http://www.example.com/some_img.jpg)' === style.background,
- 'background is different'
- );
- style.border = '0 solid black';
- test.ok('0px' === style.borderWidth, 'borderWidth is not 0px');
- test.ok('solid' === style.borderStyle, 'borderStyle is not solid');
- test.ok('black' === style.borderColor, 'borderColor is not black');
- test.ok('0px' === style.borderTopWidth, 'borderTopWidth is not 0px');
- test.ok('solid' === style.borderLeftStyle, 'borderLeftStyle is not solid');
- test.ok('black' === style.borderBottomColor, 'borderBottomColor is not black');
- style.font = '12em monospace';
- test.ok('12em' === style.fontSize, 'fontSize is not 12em');
- test.ok('monospace' === style.fontFamily, 'fontFamily is not monospace');
- test.done();
- },
- 'Test width and height Properties and null and empty strings': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(9);
- style.height = 6;
- test.ok('' === style.height, 'height does not remain unset');
- style.width = 0;
- test.ok('0px' === style.width, 'width is not 0px');
- style.height = '34%';
- test.ok('34%' === style.height, 'height is not 34%');
- style.height = '100vh';
- test.ok('100vh' === style.height, 'height is not 100vh');
- style.height = '100vw';
- test.ok('100vw' === style.height, 'height is not 100vw');
- style.height = '';
- test.ok(style.length === 1, 'length is not 1');
- test.ok('width: 0px;' === style.cssText, 'cssText is not "width: 0px;"');
- style.width = null;
- test.ok(style.length === 0, 'length is not 0');
- test.ok('' === style.cssText, 'cssText is not empty string');
- test.done();
- },
- 'Test Implicit Properties': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(7);
- style.borderWidth = 0;
- test.ok(1 === style.length, 'length is not 1');
- test.ok('0px' === style.borderWidth, 'borderWidth is not 0px');
- test.ok('0px' === style.borderTopWidth, 'borderTopWidth is not 0px');
- test.ok('0px' === style.borderBottomWidth, 'borderBottomWidth is not 0px');
- test.ok('0px' === style.borderLeftWidth, 'borderLeftWidth is not 0px');
- test.ok('0px' === style.borderRightWidth, 'borderRightWidth is not 0px');
- test.ok(
- 'border-width: 0px;' === style.cssText,
- 'cssText is not "border-width: 0px", "' + style.cssText + '"'
- );
- test.done();
- },
- 'Test Top, Left, Right, Bottom Properties': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(6);
- style.top = 0;
- style.left = '0%';
- style.right = '5em';
- style.bottom = '12pt';
- test.ok('0px' === style.top, 'top is not 0px');
- test.ok('0%' === style.left, 'left is not 0%');
- test.ok('5em' === style.right, 'right is not 5em');
- test.ok('12pt' === style.bottom, 'bottom is not 12pt');
- test.ok(4 === style.length, 'length is not 4');
- test.ok(
- 'top: 0px; left: 0%; right: 5em; bottom: 12pt;' === style.cssText,
- 'text is not "top: 0px; left: 0%; right: 5em; bottom: 12pt;"'
- );
- test.done();
- },
- 'Test Clear and Clip Properties': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(10);
- style.clear = 'none';
- test.ok('none' === style.clear, 'clear is not none');
- style.clear = 'lfet'; // intentionally wrong
- test.ok('none' === style.clear, 'clear is not still none');
- style.clear = 'left';
- test.ok('left' === style.clear, 'clear is not left');
- style.clear = 'right';
- test.ok('right' === style.clear, 'clear is not right');
- style.clear = 'both';
- test.ok('both' === style.clear, 'clear is not both');
- style.clip = 'elipse(5px, 10px)';
- test.ok('' === style.clip, 'clip should not be set');
- test.ok(1 === style.length, 'length is not 1');
- style.clip = 'rect(0, 3Em, 2pt, 50%)';
- test.ok(
- 'rect(0px, 3em, 2pt, 50%)' === style.clip,
- 'clip is not "rect(0px, 3em, 2pt, 50%)", "' + style.clip + '"'
- );
- test.ok(2 === style.length, 'length is not 2');
- test.ok(
- 'clear: both; clip: rect(0px, 3em, 2pt, 50%);' === style.cssText,
- 'cssText is not "clear: both; clip: rect(0px, 3em, 2pt, 50%);"'
- );
- test.done();
- },
- 'Test colors': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(9);
- style.color = 'rgba(0,0,0,0)';
- test.ok('rgba(0, 0, 0, 0)' === style.color, 'color is not rgba(0, 0, 0, 0)');
- style.color = 'rgba(5%, 10%, 20%, 0.4)';
- test.ok('rgba(12, 25, 51, 0.4)' === style.color, 'color is not rgba(12, 25, 51, 0.4)');
- style.color = 'rgb(33%, 34%, 33%)';
- test.ok('rgb(84, 86, 84)' === style.color, 'color is not rgb(84, 86, 84)');
- style.color = 'rgba(300, 200, 100, 1.5)';
- test.ok('rgb(255, 200, 100)' === style.color, 'color is not rgb(255, 200, 100) ' + style.color);
- style.color = 'hsla(0, 1%, 2%, 0.5)';
- test.ok(
- 'hsla(0, 1%, 2%, 0.5)' === style.color,
- 'color is not hsla(0, 1%, 2%, 0.5) ' + style.color
- );
- style.color = 'hsl(0, 1%, 2%)';
- test.ok('hsl(0, 1%, 2%)' === style.color, 'color is not hsl(0, 1%, 2%) ' + style.color);
- style.color = 'rebeccapurple';
- test.ok('rebeccapurple' === style.color, 'color is not rebeccapurple ' + style.color);
- style.color = 'transparent';
- test.ok('transparent' === style.color, 'color is not transparent ' + style.color);
- style.color = 'currentcolor';
- test.ok('currentcolor' === style.color, 'color is not currentcolor ' + style.color);
- test.done();
- },
- 'Test short hand properties with embedded spaces': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(4);
- style.background = 'rgb(0, 0, 0) url(/something/somewhere.jpg)';
- test.ok(
- 'rgb(0, 0, 0)' === style.backgroundColor,
- 'backgroundColor is not rgb(0, 0, 0): ' + style.backgroundColor
- );
- test.ok(
- 'url(/something/somewhere.jpg)' === style.backgroundImage,
- 'backgroundImage is not url(/something/somewhere.jpg): ' + style.backgroundImage
- );
- test.ok(
- 'background: rgb(0, 0, 0) url(/something/somewhere.jpg);' === style.cssText,
- 'cssText is not correct: ' + style.cssText
- );
- style = new cssstyle.CSSStyleDeclaration();
- style.border = ' 1px solid black ';
- test.ok(
- '1px solid black' === style.border,
- 'multiple spaces not properly parsed: ' + style.border
- );
- test.done();
- },
- 'Setting shorthand properties to an empty string should clear all dependent properties': function(
- test
- ) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(2);
- style.borderWidth = '1px';
- test.ok(
- 'border-width: 1px;' === style.cssText,
- 'cssText is not "border-width: 1px;": ' + style.cssText
- );
- style.border = '';
- test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
- test.done();
- },
- 'Setting implicit properties to an empty string should clear all dependent properties': function(
- test
- ) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(2);
- style.borderTopWidth = '1px';
- test.ok(
- 'border-top-width: 1px;' === style.cssText,
- 'cssText is not "border-top-width: 1px;": ' + style.cssText
- );
- style.borderWidth = '';
- test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
- test.done();
- },
- 'Setting a shorthand property, whose shorthands are implicit properties, to an empty string should clear all dependent properties': function(
- test
- ) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(4);
- style.borderTopWidth = '1px';
- test.ok(
- 'border-top-width: 1px;' === style.cssText,
- 'cssText is not "border-top-width: 1px;": ' + style.cssText
- );
- style.border = '';
- test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
- style.borderTop = '1px solid black';
- test.ok(
- 'border-top: 1px solid black;' === style.cssText,
- 'cssText is not "border-top: 1px solid black;": ' + style.cssText
- );
- style.border = '';
- test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
- test.done();
- },
- 'Setting border values to "none" should clear dependent values': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(8);
- style.borderTopWidth = '1px';
- test.ok(
- 'border-top-width: 1px;' === style.cssText,
- 'cssText is not "border-top-width: 1px;": ' + style.cssText
- );
- style.border = 'none';
- test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
- style.borderTopWidth = '1px';
- test.ok(
- 'border-top-width: 1px;' === style.cssText,
- 'cssText is not "border-top-width: 1px;": ' + style.cssText
- );
- style.borderTopStyle = 'none';
- test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
- style.borderTopWidth = '1px';
- test.ok(
- 'border-top-width: 1px;' === style.cssText,
- 'cssText is not "border-top-width: 1px;": ' + style.cssText
- );
- style.borderTop = 'none';
- test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
- style.borderTopWidth = '1px';
- style.borderLeftWidth = '1px';
- test.ok(
- 'border-top-width: 1px; border-left-width: 1px;' === style.cssText,
- 'cssText is not "border-top-width: 1px; border-left-width: 1px;": ' + style.cssText
- );
- style.borderTop = 'none';
- test.ok(
- 'border-left-width: 1px;' === style.cssText,
- 'cssText is not "border-left-width: 1px;": ' + style.cssText
- );
- test.done();
- },
- 'Setting border to 0 should be okay': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(1);
- style.border = 0;
- test.ok('border: 0px;' === style.cssText, 'cssText is not "border: 0px;": ' + style.cssText);
- test.done();
- },
- 'Setting values implicit and shorthand properties via cssText and setProperty should propagate to dependent properties': function(
- test
- ) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(4);
- style.cssText = 'border: 1px solid black;';
- test.ok(
- 'border: 1px solid black;' === style.cssText,
- 'cssText is not "border: 1px solid black;": ' + style.cssText
- );
- test.ok(
- '1px solid black' === style.borderTop,
- 'borderTop is not "1px solid black": ' + style.borderTop
- );
- style.border = '';
- test.ok('' === style.cssText, 'cssText is not "": ' + style.cssText);
- style.setProperty('border', '1px solid black');
- test.ok(
- 'border: 1px solid black;' === style.cssText,
- 'cssText is not "border: 1px solid black;": ' + style.cssText
- );
- test.done();
- },
- 'Setting opacity should work': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(3);
- style.setProperty('opacity', 0.75);
- test.ok(
- 'opacity: 0.75;' === style.cssText,
- 'cssText is not "opacity: 0.75;": ' + style.cssText
- );
- style.opacity = '0.50';
- test.ok('opacity: 0.5;' === style.cssText, 'cssText is not "opacity: 0.5;": ' + style.cssText);
- style.opacity = 1.0;
- test.ok('opacity: 1;' === style.cssText, 'cssText is not "opacity: 1;": ' + style.cssText);
- test.done();
- },
- 'Width and height of auto should work': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(4);
- style.width = 'auto';
- test.equal(style.cssText, 'width: auto;', 'cssText is not "width: auto;": ' + style.cssText);
- test.equal(style.width, 'auto', 'width is not "auto": ' + style.width);
- style = new cssstyle.CSSStyleDeclaration();
- style.height = 'auto';
- test.equal(style.cssText, 'height: auto;', 'cssText is not "height: auto;": ' + style.cssText);
- test.equal(style.height, 'auto', 'height is not "auto": ' + style.height);
- test.done();
- },
- 'Padding and margin should set/clear shorthand properties': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- var parts = ['Top', 'Right', 'Bottom', 'Left'];
- var testParts = function(name, v, V) {
- style[name] = v;
- for (var i = 0; i < 4; i++) {
- var part = name + parts[i];
- test.equal(V[i], style[part], part + ' is not "' + V[i] + '": "' + style[part] + '"');
- }
- test.equal(v, style[name], name + ' is not "' + v + '": "' + style[name] + '"');
- style[name] = '';
- };
- test.expect(50);
- testParts('padding', '1px', ['1px', '1px', '1px', '1px']);
- testParts('padding', '1px 2%', ['1px', '2%', '1px', '2%']);
- testParts('padding', '1px 2px 3px', ['1px', '2px', '3px', '2px']);
- testParts('padding', '1px 2px 3px 4px', ['1px', '2px', '3px', '4px']);
- style.paddingTop = style.paddingRight = style.paddingBottom = style.paddingLeft = '1px';
- testParts('padding', '', ['', '', '', '']);
- testParts('margin', '1px', ['1px', '1px', '1px', '1px']);
- testParts('margin', '1px auto', ['1px', 'auto', '1px', 'auto']);
- testParts('margin', '1px 2% 3px', ['1px', '2%', '3px', '2%']);
- testParts('margin', '1px 2px 3px 4px', ['1px', '2px', '3px', '4px']);
- style.marginTop = style.marginRight = style.marginBottom = style.marginLeft = '1px';
- testParts('margin', '', ['', '', '', '']);
- test.done();
- },
- 'Padding and margin shorthands should set main properties': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- var parts = ['Top', 'Right', 'Bottom', 'Left'];
- var testParts = function(name, v, V) {
- var expect;
- for (var i = 0; i < 4; i++) {
- style[name] = v;
- style[name + parts[i]] = V;
- expect = v.split(/ /);
- expect[i] = V;
- expect = expect.join(' ');
- test.equal(expect, style[name], name + ' is not "' + expect + '": "' + style[name] + '"');
- }
- };
- test.expect(12);
- testParts('padding', '1px 2px 3px 4px', '10px');
- testParts('margin', '1px 2px 3px 4px', '10px');
- testParts('margin', '1px 2px 3px 4px', 'auto');
- test.done();
- },
- 'Setting a value to 0 should return the string value': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(1);
- style.setProperty('fill-opacity', 0);
- test.ok('0' === style.fillOpacity, 'fillOpacity is not "0": ' + style.fillOpacity);
- test.done();
- },
- 'onChange callback should be called when the cssText changes': function(test) {
- var style = new cssstyle.CSSStyleDeclaration(function(cssText) {
- test.ok('opacity: 0;' === cssText, 'cssText is not "opacity: 0;": ' + cssText);
- test.done();
- });
- test.expect(1);
- style.setProperty('opacity', 0);
- },
- 'Setting float should work the same as cssFloat': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(1);
- style.float = 'left';
- test.ok('left' === style.cssFloat, 'cssFloat is not "left": ' + style.cssFloat);
- test.done();
- },
- 'Setting improper css to cssText should not throw': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(2);
- style.cssText = 'color: ';
- test.ok('' === style.cssText, "cssText wasn't cleared: " + style.cssText);
- style.color = 'black';
- style.cssText = 'float: ';
- test.ok('' === style.cssText, "cssText wasn't cleared: " + style.cssText);
- test.done();
- },
- 'Make sure url parsing works with quotes': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(3);
- style.backgroundImage = 'url(http://some/url/here1.png)';
- test.ok(
- 'url(http://some/url/here1.png)' === style.backgroundImage,
- "background-image wasn't url(http://some/url/here1.png): " + style.backgroundImage
- );
- style.backgroundImage = "url('http://some/url/here2.png')";
- test.ok(
- 'url(http://some/url/here2.png)' === style.backgroundImage,
- "background-image wasn't url(http://some/url/here2.png): " + style.backgroundImage
- );
- style.backgroundImage = 'url("http://some/url/here3.png")';
- test.ok(
- 'url(http://some/url/here3.png)' === style.backgroundImage,
- "background-image wasn't url(http://some/url/here3.png): " + style.backgroundImage
- );
- test.done();
- },
- 'Make sure setting 0 to a padding or margin works': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(2);
- style.padding = 0;
- test.equal(style.cssText, 'padding: 0px;', 'padding is not 0px');
- style.margin = '1em';
- style.marginTop = '0';
- test.equal(style.marginTop, '0px', 'margin-top is not 0px');
- test.done();
- },
- 'Make sure setting ex units to a padding or margin works': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(2);
- style.padding = '1ex';
- test.equal(style.cssText, 'padding: 1ex;', 'padding is not 1ex');
- style.margin = '1em';
- style.marginTop = '0.5ex';
- test.equal(style.marginTop, '0.5ex', 'margin-top is not 0.5ex');
- test.done();
- },
- 'Make sure setting null to background works': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(2);
- style.background = 'red';
- test.equal(style.cssText, 'background: red;', 'background is not red');
- style.background = null;
- test.equal(style.cssText, '', 'cssText is not empty');
- test.done();
- },
- 'Flex properties should keep their values': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(2);
- style.flexDirection = 'column';
- test.equal(style.cssText, 'flex-direction: column;', 'flex-direction is not column');
- style.flexDirection = 'row';
- test.equal(style.cssText, 'flex-direction: row;', 'flex-direction is not column');
- test.done();
- },
- 'Make sure camelCase properties are not assigned with `.setProperty()`': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(1);
- style.setProperty('fontSize', '12px');
- test.equal(style.cssText, '', 'cssText is not empty');
- test.done();
- },
- 'Make sure casing is ignored in `.setProperty()`': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(2);
- style.setProperty('FoNt-SiZe', '12px');
- test.equal(style.fontSize, '12px', 'font-size: 12px');
- test.equal(style.getPropertyValue('font-size'), '12px', 'font-size: 12px');
- test.done();
- },
- 'Support non string entries in border-spacing': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(1);
- style.borderSpacing = 0;
- test.equal(style.cssText, 'border-spacing: 0px;', 'border-spacing is not 0');
- test.done();
- },
- 'Float should be valid property for `.setProperty()`': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(2);
- style.setProperty('float', 'left');
- test.equal(style.float, 'left');
- test.equal(style.getPropertyValue('float'), 'left', 'float: left');
- test.done();
- },
- 'Make sure flex-shrink works': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(3);
- style.setProperty('flex-shrink', 0);
- test.equal(style.getPropertyValue('flex-shrink'), '0', 'flex-shrink is not 0');
- style.setProperty('flex-shrink', 1);
- test.equal(style.getPropertyValue('flex-shrink'), '1', 'flex-shrink is not 1');
- test.equal(style.cssText, 'flex-shrink: 1;', 'flex-shrink cssText is incorrect');
- test.done();
- },
- 'Make sure flex-grow works': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(2);
- style.setProperty('flex-grow', 2);
- test.equal(style.getPropertyValue('flex-grow'), '2', 'flex-grow is not 2');
- test.equal(style.cssText, 'flex-grow: 2;', 'flex-grow cssText is incorrect');
- test.done();
- },
- 'Make sure flex-basis works': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(5);
- style.setProperty('flex-basis', 0);
- test.equal(style.getPropertyValue('flex-basis'), '0px', 'flex-basis is not 0px');
- style.setProperty('flex-basis', '250px');
- test.equal(style.getPropertyValue('flex-basis'), '250px', 'flex-basis is not 250px');
- style.setProperty('flex-basis', '10em');
- test.equal(style.getPropertyValue('flex-basis'), '10em', 'flex-basis is not 10em');
- style.setProperty('flex-basis', '30%');
- test.equal(style.getPropertyValue('flex-basis'), '30%', 'flex-basis is not 30%');
- test.equal(style.cssText, 'flex-basis: 30%;', 'flex-basis cssText is incorrect');
- test.done();
- },
- 'Make sure shorthand flex works': function(test) {
- var style = new cssstyle.CSSStyleDeclaration();
- test.expect(19);
- style.setProperty('flex', 'none');
- test.equal(style.getPropertyValue('flex-grow'), '0', 'flex-grow is not 0 if flex: none;');
- test.equal(style.getPropertyValue('flex-shrink'), '0', 'flex-shrink is not 0 if flex: none;');
- test.equal(
- style.getPropertyValue('flex-basis'),
- 'auto',
- 'flex-basis is not `auto` if flex: none;'
- );
- style.removeProperty('flex');
- style.removeProperty('flex-basis');
- style.setProperty('flex', 'auto');
- test.equal(style.getPropertyValue('flex-grow'), '', 'flex-grow is not empty if flex: auto;');
- test.equal(
- style.getPropertyValue('flex-shrink'),
- '',
- 'flex-shrink is not empty if flex: auto;'
- );
- test.equal(
- style.getPropertyValue('flex-basis'),
- 'auto',
- 'flex-basis is not `auto` if flex: auto;'
- );
- style.removeProperty('flex');
- style.setProperty('flex', '0 1 250px');
- test.equal(style.getPropertyValue('flex'), '0 1 250px', 'flex value is not `0 1 250px`');
- test.equal(style.getPropertyValue('flex-grow'), '0', 'flex-grow is not 0');
- test.equal(style.getPropertyValue('flex-shrink'), '1', 'flex-shrink is not 1');
- test.equal(style.getPropertyValue('flex-basis'), '250px', 'flex-basis is not 250px');
- style.removeProperty('flex');
- style.setProperty('flex', '2');
- test.equal(style.getPropertyValue('flex-grow'), '2', 'flex-grow is not 2');
- test.equal(style.getPropertyValue('flex-shrink'), '', 'flex-shrink is not empty');
- test.equal(style.getPropertyValue('flex-basis'), '', 'flex-basis is not empty');
- style.removeProperty('flex');
- style.setProperty('flex', '20%');
- test.equal(style.getPropertyValue('flex-grow'), '', 'flex-grow is not empty');
- test.equal(style.getPropertyValue('flex-shrink'), '', 'flex-shrink is not empty');
- test.equal(style.getPropertyValue('flex-basis'), '20%', 'flex-basis is not 20%');
- style.removeProperty('flex');
- style.setProperty('flex', '2 2');
- test.equal(style.getPropertyValue('flex-grow'), '2', 'flex-grow is not 2');
- test.equal(style.getPropertyValue('flex-shrink'), '2', 'flex-shrink is not 2');
- test.equal(style.getPropertyValue('flex-basis'), '', 'flex-basis is not empty');
- style.removeProperty('flex');
- test.done();
- },
- };
|