style.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. jsdom = require('../../lib/jsdom');
  2. assert = require('assert')
  3. exports.tests = {
  4. HTMLStyleElement01 : function (test) {
  5. jsdom.env(
  6. '<html><head><style>p{color:red}</style></head><body>',
  7. jsdom.defaultLevel, function(err, win) {
  8. var style = win.document.head.lastChild;
  9. test.equal(1, style.sheet.cssRules.length);
  10. test.equal('p', style.sheet.cssRules[0].selectorText);
  11. test.equal('red', style.sheet.cssRules[0].style.color);
  12. test.done();
  13. });
  14. },
  15. HTMLStyleAttribute01 : function (test) {
  16. jsdom.env(
  17. '<html><body><p style="color:red">',
  18. jsdom.defaultLevel, function(err, win) {
  19. var p = win.document.body.lastChild;
  20. test.equal(1, p.style.length);
  21. test.equal('color', p.style[0]);
  22. test.equal('red', p.style.color);
  23. test.done();
  24. });
  25. },
  26. StylePropertyReflectsStyleAttribute : function (test) {
  27. jsdom.env(
  28. '<html>',
  29. jsdom.defaultLevel, function(err, win) {
  30. var p = win.document.createElement('p');
  31. p.setAttribute('style', 'color:red');
  32. test.equal(1, p.style.length);
  33. test.equal('color', p.style[0]);
  34. test.equal('red', p.style.color);
  35. p.setAttribute('style', '');
  36. test.equal(0, p.style.length);
  37. test.equal('', p.style.color);
  38. p.setAttribute('style', 'color:blue');
  39. test.equal('color', p.style[0]);
  40. test.equal('blue', p.style.color);
  41. test.done();
  42. });
  43. },
  44. // TODO: the other way should work too: setting p.style.color
  45. // should modify p.getAttribute('style').
  46. // We will have to fork or modify cssom library to listen for change events.
  47. }