CSSStyleDeclaration.test.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. 'use strict';
  2. var { CSSStyleDeclaration } = require('./CSSStyleDeclaration');
  3. var allProperties = require('./allProperties');
  4. var allExtraProperties = require('./allExtraProperties');
  5. var implementedProperties = require('./implementedProperties');
  6. var parsers = require('./parsers');
  7. var dashedProperties = [...allProperties, ...allExtraProperties];
  8. var allowedProperties = dashedProperties.map(parsers.dashedToCamelCase);
  9. implementedProperties = Array.from(implementedProperties).map(parsers.dashedToCamelCase);
  10. var invalidProperties = implementedProperties.filter(prop => !allowedProperties.includes(prop));
  11. describe('CSSStyleDeclaration', () => {
  12. test('has only valid properties implemented', () => {
  13. expect(invalidProperties.length).toEqual(0);
  14. });
  15. test('has all properties', () => {
  16. var style = new CSSStyleDeclaration();
  17. allProperties.forEach(property => {
  18. expect(style.__lookupGetter__(property)).toBeTruthy();
  19. expect(style.__lookupSetter__(property)).toBeTruthy();
  20. });
  21. });
  22. test('has dashed properties', () => {
  23. var style = new CSSStyleDeclaration();
  24. dashedProperties.forEach(property => {
  25. expect(style.__lookupGetter__(property)).toBeTruthy();
  26. expect(style.__lookupSetter__(property)).toBeTruthy();
  27. });
  28. });
  29. test('has all functions', () => {
  30. var style = new CSSStyleDeclaration();
  31. expect(typeof style.item).toEqual('function');
  32. expect(typeof style.getPropertyValue).toEqual('function');
  33. expect(typeof style.setProperty).toEqual('function');
  34. expect(typeof style.getPropertyPriority).toEqual('function');
  35. expect(typeof style.removeProperty).toEqual('function');
  36. // TODO - deprecated according to MDN and not implemented at all, can we remove?
  37. expect(typeof style.getPropertyCSSValue).toEqual('function');
  38. });
  39. test('has special properties', () => {
  40. var style = new CSSStyleDeclaration();
  41. expect(style.__lookupGetter__('cssText')).toBeTruthy();
  42. expect(style.__lookupSetter__('cssText')).toBeTruthy();
  43. expect(style.__lookupGetter__('length')).toBeTruthy();
  44. expect(style.__lookupSetter__('length')).toBeTruthy();
  45. expect(style.__lookupGetter__('parentRule')).toBeTruthy();
  46. });
  47. test('from style string', () => {
  48. var style = new CSSStyleDeclaration();
  49. style.cssText = 'color: blue; background-color: red; width: 78%; height: 50vh;';
  50. expect(style.length).toEqual(4);
  51. expect(style.cssText).toEqual('color: blue; background-color: red; width: 78%; height: 50vh;');
  52. expect(style.getPropertyValue('color')).toEqual('blue');
  53. expect(style.item(0)).toEqual('color');
  54. expect(style[1]).toEqual('background-color');
  55. expect(style.backgroundColor).toEqual('red');
  56. style.cssText = '';
  57. expect(style.cssText).toEqual('');
  58. expect(style.length).toEqual(0);
  59. });
  60. test('from properties', () => {
  61. var style = new CSSStyleDeclaration();
  62. style.color = 'blue';
  63. expect(style.length).toEqual(1);
  64. expect(style[0]).toEqual('color');
  65. expect(style.cssText).toEqual('color: blue;');
  66. expect(style.item(0)).toEqual('color');
  67. expect(style.color).toEqual('blue');
  68. style.backgroundColor = 'red';
  69. expect(style.length).toEqual(2);
  70. expect(style[0]).toEqual('color');
  71. expect(style[1]).toEqual('background-color');
  72. expect(style.cssText).toEqual('color: blue; background-color: red;');
  73. expect(style.backgroundColor).toEqual('red');
  74. style.removeProperty('color');
  75. expect(style[0]).toEqual('background-color');
  76. });
  77. test('shorthand properties', () => {
  78. var style = new CSSStyleDeclaration();
  79. style.background = 'blue url(http://www.example.com/some_img.jpg)';
  80. expect(style.backgroundColor).toEqual('blue');
  81. expect(style.backgroundImage).toEqual('url(http://www.example.com/some_img.jpg)');
  82. expect(style.background).toEqual('blue url(http://www.example.com/some_img.jpg)');
  83. style.border = '0 solid black';
  84. expect(style.borderWidth).toEqual('0px');
  85. expect(style.borderStyle).toEqual('solid');
  86. expect(style.borderColor).toEqual('black');
  87. expect(style.borderTopWidth).toEqual('0px');
  88. expect(style.borderLeftStyle).toEqual('solid');
  89. expect(style.borderBottomColor).toEqual('black');
  90. style.font = '12em monospace';
  91. expect(style.fontSize).toEqual('12em');
  92. expect(style.fontFamily).toEqual('monospace');
  93. });
  94. test('width and height properties and null and empty strings', () => {
  95. var style = new CSSStyleDeclaration();
  96. style.height = 6;
  97. expect(style.height).toEqual('');
  98. style.width = 0;
  99. expect(style.width).toEqual('0px');
  100. style.height = '34%';
  101. expect(style.height).toEqual('34%');
  102. style.height = '100vh';
  103. expect(style.height).toEqual('100vh');
  104. style.height = '100vw';
  105. expect(style.height).toEqual('100vw');
  106. style.height = '';
  107. expect(1).toEqual(style.length);
  108. expect(style.cssText).toEqual('width: 0px;');
  109. style.width = null;
  110. expect(0).toEqual(style.length);
  111. expect(style.cssText).toEqual('');
  112. });
  113. test('implicit properties', () => {
  114. var style = new CSSStyleDeclaration();
  115. style.borderWidth = 0;
  116. expect(style.length).toEqual(1);
  117. expect(style.borderWidth).toEqual('0px');
  118. expect(style.borderTopWidth).toEqual('0px');
  119. expect(style.borderBottomWidth).toEqual('0px');
  120. expect(style.borderLeftWidth).toEqual('0px');
  121. expect(style.borderRightWidth).toEqual('0px');
  122. expect(style.cssText).toEqual('border-width: 0px;');
  123. });
  124. test('top, left, right, bottom properties', () => {
  125. var style = new CSSStyleDeclaration();
  126. style.top = 0;
  127. style.left = '0%';
  128. style.right = '5em';
  129. style.bottom = '12pt';
  130. expect(style.top).toEqual('0px');
  131. expect(style.left).toEqual('0%');
  132. expect(style.right).toEqual('5em');
  133. expect(style.bottom).toEqual('12pt');
  134. expect(style.length).toEqual(4);
  135. expect(style.cssText).toEqual('top: 0px; left: 0%; right: 5em; bottom: 12pt;');
  136. });
  137. test('clear and clip properties', () => {
  138. var style = new CSSStyleDeclaration();
  139. style.clear = 'none';
  140. expect(style.clear).toEqual('none');
  141. style.clear = 'lfet';
  142. expect(style.clear).toEqual('none');
  143. style.clear = 'left';
  144. expect(style.clear).toEqual('left');
  145. style.clear = 'right';
  146. expect(style.clear).toEqual('right');
  147. style.clear = 'both';
  148. expect(style.clear).toEqual('both');
  149. style.clip = 'elipse(5px, 10px)';
  150. expect(style.clip).toEqual('');
  151. expect(style.length).toEqual(1);
  152. style.clip = 'rect(0, 3Em, 2pt, 50%)';
  153. expect(style.clip).toEqual('rect(0px, 3em, 2pt, 50%)');
  154. expect(style.length).toEqual(2);
  155. expect(style.cssText).toEqual('clear: both; clip: rect(0px, 3em, 2pt, 50%);');
  156. });
  157. test('colors', () => {
  158. var style = new CSSStyleDeclaration();
  159. style.color = 'rgba(0,0,0,0)';
  160. expect(style.color).toEqual('rgba(0, 0, 0, 0)');
  161. style.color = 'rgba(5%, 10%, 20%, 0.4)';
  162. expect(style.color).toEqual('rgba(12, 25, 51, 0.4)');
  163. style.color = 'rgb(33%, 34%, 33%)';
  164. expect(style.color).toEqual('rgb(84, 86, 84)');
  165. style.color = 'rgba(300, 200, 100, 1.5)';
  166. expect(style.color).toEqual('rgb(255, 200, 100)');
  167. style.color = 'hsla(0, 1%, 2%, 0.5)';
  168. expect(style.color).toEqual('rgba(5, 5, 5, 0.5)');
  169. style.color = 'hsl(0, 1%, 2%)';
  170. expect(style.color).toEqual('rgb(5, 5, 5)');
  171. style.color = 'rebeccapurple';
  172. expect(style.color).toEqual('rebeccapurple');
  173. style.color = 'transparent';
  174. expect(style.color).toEqual('transparent');
  175. style.color = 'currentcolor';
  176. expect(style.color).toEqual('currentcolor');
  177. style.color = '#ffffffff';
  178. expect(style.color).toEqual('rgba(255, 255, 255, 1)');
  179. style.color = '#fffa';
  180. expect(style.color).toEqual('rgba(255, 255, 255, 0.667)');
  181. style.color = '#ffffff66';
  182. expect(style.color).toEqual('rgba(255, 255, 255, 0.4)');
  183. });
  184. test('short hand properties with embedded spaces', () => {
  185. var style = new CSSStyleDeclaration();
  186. style.background = 'rgb(0, 0, 0) url(/something/somewhere.jpg)';
  187. expect(style.backgroundColor).toEqual('rgb(0, 0, 0)');
  188. expect(style.backgroundImage).toEqual('url(/something/somewhere.jpg)');
  189. expect(style.cssText).toEqual('background: rgb(0, 0, 0) url(/something/somewhere.jpg);');
  190. style = new CSSStyleDeclaration();
  191. style.border = ' 1px solid black ';
  192. expect(style.border).toEqual('1px solid black');
  193. });
  194. test('setting shorthand properties to an empty string should clear all dependent properties', () => {
  195. var style = new CSSStyleDeclaration();
  196. style.borderWidth = '1px';
  197. expect(style.cssText).toEqual('border-width: 1px;');
  198. style.border = '';
  199. expect(style.cssText).toEqual('');
  200. });
  201. test('setting implicit properties to an empty string should clear all dependent properties', () => {
  202. var style = new CSSStyleDeclaration();
  203. style.borderTopWidth = '1px';
  204. expect(style.cssText).toEqual('border-top-width: 1px;');
  205. style.borderWidth = '';
  206. expect(style.cssText).toEqual('');
  207. });
  208. test('setting a shorthand property, whose shorthands are implicit properties, to an empty string should clear all dependent properties', () => {
  209. var style = new CSSStyleDeclaration();
  210. style.borderTopWidth = '1px';
  211. expect(style.cssText).toEqual('border-top-width: 1px;');
  212. style.border = '';
  213. expect(style.cssText).toEqual('');
  214. style.borderTop = '1px solid black';
  215. expect(style.cssText).toEqual('border-top: 1px solid black;');
  216. style.border = '';
  217. expect(style.cssText).toEqual('');
  218. });
  219. test('setting border values to "none" should clear dependent values', () => {
  220. var style = new CSSStyleDeclaration();
  221. style.borderTopWidth = '1px';
  222. expect(style.cssText).toEqual('border-top-width: 1px;');
  223. style.border = 'none';
  224. expect(style.cssText).toEqual('');
  225. style.borderTopWidth = '1px';
  226. expect(style.cssText).toEqual('border-top-width: 1px;');
  227. style.borderTopStyle = 'none';
  228. expect(style.cssText).toEqual('');
  229. style.borderTopWidth = '1px';
  230. expect(style.cssText).toEqual('border-top-width: 1px;');
  231. style.borderTop = 'none';
  232. expect(style.cssText).toEqual('');
  233. style.borderTopWidth = '1px';
  234. style.borderLeftWidth = '1px';
  235. expect(style.cssText).toEqual('border-top-width: 1px; border-left-width: 1px;');
  236. style.borderTop = 'none';
  237. expect(style.cssText).toEqual('border-left-width: 1px;');
  238. });
  239. test('setting border to 0 should be okay', () => {
  240. var style = new CSSStyleDeclaration();
  241. style.border = 0;
  242. expect(style.cssText).toEqual('border: 0px;');
  243. });
  244. test('setting values implicit and shorthand properties via csstext and setproperty should propagate to dependent properties', () => {
  245. var style = new CSSStyleDeclaration();
  246. style.cssText = 'border: 1px solid black;';
  247. expect(style.cssText).toEqual('border: 1px solid black;');
  248. expect(style.borderTop).toEqual('1px solid black');
  249. style.border = '';
  250. expect(style.cssText).toEqual('');
  251. style.setProperty('border', '1px solid black');
  252. expect(style.cssText).toEqual('border: 1px solid black;');
  253. });
  254. test('setting opacity should work', () => {
  255. var style = new CSSStyleDeclaration();
  256. style.setProperty('opacity', 0.75);
  257. expect(style.cssText).toEqual('opacity: 0.75;');
  258. style.opacity = '0.50';
  259. expect(style.cssText).toEqual('opacity: 0.5;');
  260. style.opacity = 1;
  261. expect(style.cssText).toEqual('opacity: 1;');
  262. });
  263. test('width and height of auto should work', () => {
  264. var style = new CSSStyleDeclaration();
  265. style.width = 'auto';
  266. expect(style.cssText).toEqual('width: auto;');
  267. expect(style.width).toEqual('auto');
  268. style = new CSSStyleDeclaration();
  269. style.height = 'auto';
  270. expect(style.cssText).toEqual('height: auto;');
  271. expect(style.height).toEqual('auto');
  272. });
  273. test('padding and margin should set/clear shorthand properties', () => {
  274. var style = new CSSStyleDeclaration();
  275. var parts = ['Top', 'Right', 'Bottom', 'Left'];
  276. var testParts = function(name, v, V) {
  277. style[name] = v;
  278. for (var i = 0; i < 4; i++) {
  279. var part = name + parts[i];
  280. expect(style[part]).toEqual(V[i]);
  281. }
  282. expect(style[name]).toEqual(v);
  283. style[name] = '';
  284. };
  285. testParts('padding', '1px', ['1px', '1px', '1px', '1px']);
  286. testParts('padding', '1px 2%', ['1px', '2%', '1px', '2%']);
  287. testParts('padding', '1px 2px 3px', ['1px', '2px', '3px', '2px']);
  288. testParts('padding', '1px 2px 3px 4px', ['1px', '2px', '3px', '4px']);
  289. style.paddingTop = style.paddingRight = style.paddingBottom = style.paddingLeft = '1px';
  290. testParts('padding', '', ['', '', '', '']);
  291. testParts('margin', '1px', ['1px', '1px', '1px', '1px']);
  292. testParts('margin', '1px auto', ['1px', 'auto', '1px', 'auto']);
  293. testParts('margin', '1px 2% 3px', ['1px', '2%', '3px', '2%']);
  294. testParts('margin', '1px 2px 3px 4px', ['1px', '2px', '3px', '4px']);
  295. style.marginTop = style.marginRight = style.marginBottom = style.marginLeft = '1px';
  296. testParts('margin', '', ['', '', '', '']);
  297. });
  298. test('padding and margin shorthands should set main properties', () => {
  299. var style = new CSSStyleDeclaration();
  300. var parts = ['Top', 'Right', 'Bottom', 'Left'];
  301. var testParts = function(name, v, V) {
  302. var expected;
  303. for (var i = 0; i < 4; i++) {
  304. style[name] = v;
  305. style[name + parts[i]] = V;
  306. expected = v.split(/ /);
  307. expected[i] = V;
  308. expected = expected.join(' ');
  309. expect(style[name]).toEqual(expected);
  310. }
  311. };
  312. testParts('padding', '1px 2px 3px 4px', '10px');
  313. testParts('margin', '1px 2px 3px 4px', '10px');
  314. testParts('margin', '1px 2px 3px 4px', 'auto');
  315. });
  316. test('setting a value to 0 should return the string value', () => {
  317. var style = new CSSStyleDeclaration();
  318. style.setProperty('fill-opacity', 0);
  319. expect(style.fillOpacity).toEqual('0');
  320. });
  321. test('onchange callback should be called when the csstext changes', () => {
  322. var style = new CSSStyleDeclaration(function(cssText) {
  323. expect(cssText).toEqual('opacity: 0;');
  324. });
  325. style.setProperty('opacity', 0);
  326. });
  327. test('setting float should work the same as cssfloat', () => {
  328. var style = new CSSStyleDeclaration();
  329. style.float = 'left';
  330. expect(style.cssFloat).toEqual('left');
  331. });
  332. test('setting improper css to csstext should not throw', () => {
  333. var style = new CSSStyleDeclaration();
  334. style.cssText = 'color: ';
  335. expect(style.cssText).toEqual('');
  336. style.color = 'black';
  337. style.cssText = 'float: ';
  338. expect(style.cssText).toEqual('');
  339. });
  340. test('url parsing works with quotes', () => {
  341. var style = new CSSStyleDeclaration();
  342. style.backgroundImage = 'url(http://some/url/here1.png)';
  343. expect(style.backgroundImage).toEqual('url(http://some/url/here1.png)');
  344. style.backgroundImage = "url('http://some/url/here2.png')";
  345. expect(style.backgroundImage).toEqual('url(http://some/url/here2.png)');
  346. style.backgroundImage = 'url("http://some/url/here3.png")';
  347. expect(style.backgroundImage).toEqual('url(http://some/url/here3.png)');
  348. });
  349. test('setting 0 to a padding or margin works', () => {
  350. var style = new CSSStyleDeclaration();
  351. style.padding = 0;
  352. expect(style.cssText).toEqual('padding: 0px;');
  353. style.margin = '1em';
  354. style.marginTop = '0';
  355. expect(style.marginTop).toEqual('0px');
  356. });
  357. test('setting ex units to a padding or margin works', () => {
  358. var style = new CSSStyleDeclaration();
  359. style.padding = '1ex';
  360. expect(style.cssText).toEqual('padding: 1ex;');
  361. style.margin = '1em';
  362. style.marginTop = '0.5ex';
  363. expect(style.marginTop).toEqual('0.5ex');
  364. });
  365. test('setting null to background works', () => {
  366. var style = new CSSStyleDeclaration();
  367. style.background = 'red';
  368. expect(style.cssText).toEqual('background: red;');
  369. style.background = null;
  370. expect(style.cssText).toEqual('');
  371. });
  372. test('flex properties should keep their values', () => {
  373. var style = new CSSStyleDeclaration();
  374. style.flexDirection = 'column';
  375. expect(style.cssText).toEqual('flex-direction: column;');
  376. style.flexDirection = 'row';
  377. expect(style.cssText).toEqual('flex-direction: row;');
  378. });
  379. test('camelcase properties are not assigned with `.setproperty()`', () => {
  380. var style = new CSSStyleDeclaration();
  381. style.setProperty('fontSize', '12px');
  382. expect(style.cssText).toEqual('');
  383. });
  384. test('casing is ignored in `.setproperty()`', () => {
  385. var style = new CSSStyleDeclaration();
  386. style.setProperty('FoNt-SiZe', '12px');
  387. expect(style.fontSize).toEqual('12px');
  388. expect(style.getPropertyValue('font-size')).toEqual('12px');
  389. });
  390. test('support non string entries in border-spacing', () => {
  391. var style = new CSSStyleDeclaration();
  392. style.borderSpacing = 0;
  393. expect(style.cssText).toEqual('border-spacing: 0px;');
  394. });
  395. test('float should be valid property for `.setproperty()`', () => {
  396. var style = new CSSStyleDeclaration();
  397. style.setProperty('float', 'left');
  398. expect(style.float).toEqual('left');
  399. expect(style.getPropertyValue('float')).toEqual('left');
  400. });
  401. test('flex-shrink works', () => {
  402. var style = new CSSStyleDeclaration();
  403. style.setProperty('flex-shrink', 0);
  404. expect(style.getPropertyValue('flex-shrink')).toEqual('0');
  405. style.setProperty('flex-shrink', 1);
  406. expect(style.getPropertyValue('flex-shrink')).toEqual('1');
  407. expect(style.cssText).toEqual('flex-shrink: 1;');
  408. });
  409. test('flex-grow works', () => {
  410. var style = new CSSStyleDeclaration();
  411. style.setProperty('flex-grow', 2);
  412. expect(style.getPropertyValue('flex-grow')).toEqual('2');
  413. expect(style.cssText).toEqual('flex-grow: 2;');
  414. });
  415. test('flex-basis works', () => {
  416. var style = new CSSStyleDeclaration();
  417. style.setProperty('flex-basis', 0);
  418. expect(style.getPropertyValue('flex-basis')).toEqual('0px');
  419. style.setProperty('flex-basis', '250px');
  420. expect(style.getPropertyValue('flex-basis')).toEqual('250px');
  421. style.setProperty('flex-basis', '10em');
  422. expect(style.getPropertyValue('flex-basis')).toEqual('10em');
  423. style.setProperty('flex-basis', '30%');
  424. expect(style.getPropertyValue('flex-basis')).toEqual('30%');
  425. expect(style.cssText).toEqual('flex-basis: 30%;');
  426. });
  427. test('shorthand flex works', () => {
  428. var style = new CSSStyleDeclaration();
  429. style.setProperty('flex', 'none');
  430. expect(style.getPropertyValue('flex-grow')).toEqual('0');
  431. expect(style.getPropertyValue('flex-shrink')).toEqual('0');
  432. expect(style.getPropertyValue('flex-basis')).toEqual('auto');
  433. style.removeProperty('flex');
  434. style.removeProperty('flex-basis');
  435. style.setProperty('flex', 'auto');
  436. expect(style.getPropertyValue('flex-grow')).toEqual('');
  437. expect(style.getPropertyValue('flex-shrink')).toEqual('');
  438. expect(style.getPropertyValue('flex-basis')).toEqual('auto');
  439. style.removeProperty('flex');
  440. style.setProperty('flex', '0 1 250px');
  441. expect(style.getPropertyValue('flex')).toEqual('0 1 250px');
  442. expect(style.getPropertyValue('flex-grow')).toEqual('0');
  443. expect(style.getPropertyValue('flex-shrink')).toEqual('1');
  444. expect(style.getPropertyValue('flex-basis')).toEqual('250px');
  445. style.removeProperty('flex');
  446. style.setProperty('flex', '2');
  447. expect(style.getPropertyValue('flex-grow')).toEqual('2');
  448. expect(style.getPropertyValue('flex-shrink')).toEqual('');
  449. expect(style.getPropertyValue('flex-basis')).toEqual('');
  450. style.removeProperty('flex');
  451. style.setProperty('flex', '20%');
  452. expect(style.getPropertyValue('flex-grow')).toEqual('');
  453. expect(style.getPropertyValue('flex-shrink')).toEqual('');
  454. expect(style.getPropertyValue('flex-basis')).toEqual('20%');
  455. style.removeProperty('flex');
  456. style.setProperty('flex', '2 2');
  457. expect(style.getPropertyValue('flex-grow')).toEqual('2');
  458. expect(style.getPropertyValue('flex-shrink')).toEqual('2');
  459. expect(style.getPropertyValue('flex-basis')).toEqual('');
  460. style.removeProperty('flex');
  461. });
  462. test('font-size get a valid value', () => {
  463. var style = new CSSStyleDeclaration();
  464. const invalidValue = '1r5px';
  465. style.cssText = 'font-size: 15px';
  466. expect(1).toEqual(style.length);
  467. style.cssText = `font-size: ${invalidValue}`;
  468. expect(0).toEqual(style.length);
  469. expect(undefined).toEqual(style[0]);
  470. });
  471. test('getPropertyValue for custom properties in cssText', () => {
  472. const style = new CSSStyleDeclaration();
  473. style.cssText = '--foo: red';
  474. expect(style.getPropertyValue('--foo')).toEqual('red');
  475. });
  476. test('getPropertyValue for custom properties with setProperty', () => {
  477. const style = new CSSStyleDeclaration();
  478. style.setProperty('--bar', 'blue');
  479. expect(style.getPropertyValue('--bar')).toEqual('blue');
  480. });
  481. test('getPropertyValue for custom properties with object setter', () => {
  482. const style = new CSSStyleDeclaration();
  483. style['--baz'] = 'yellow';
  484. expect(style.getPropertyValue('--baz')).toEqual('');
  485. });
  486. test('custom properties are case-sensitive', () => {
  487. const style = new CSSStyleDeclaration();
  488. style.cssText = '--fOo: purple';
  489. expect(style.getPropertyValue('--foo')).toEqual('');
  490. expect(style.getPropertyValue('--fOo')).toEqual('purple');
  491. });
  492. test('supports calc', () => {
  493. const style = new CSSStyleDeclaration();
  494. style.setProperty('width', 'calc(100% - 100px)');
  495. expect(style.getPropertyValue('width')).toEqual('calc(100% - 100px)');
  496. });
  497. });