jsdom / cssstyle

A Node.js implementation of the CSS Object Model CSSStyleDeclaration interface
MIT License
109 stars 70 forks source link

padding/margin not completely fixed #37

Closed domenic closed 8 years ago

domenic commented 8 years ago

https://github.com/chad3814/CSSStyleDeclaration/pull/35 helped but it seems like the sub-properties are not properly passed to the parent.

Test case from jsdom (with latest csstyle). Mostly passing except the one failing line.

const document = jsdom.jsdom();

for (const prop of ["padding", "margin"]) {
  document.body.style[prop] = "1px 2px 3px 4px";

  t.strictEqual(document.body.style[prop], "1px 2px 3px 4px");
  t.strictEqual(document.body.style[prop + "Top"], "1px");
  t.strictEqual(document.body.style[prop + "Right"], "2px");
  t.strictEqual(document.body.style[prop + "Bottom"], "3px");
  t.strictEqual(document.body.style[prop + "Left"], "4px");

  document.body.style[prop + "Top"] = "1em";
  document.body.style[prop + "Right"] = "2em";
  document.body.style[prop + "Bottom"] = "3em";
  document.body.style[prop + "Left"] = "4em";
  t.strictEqual(document.body.style[prop], "1em 2em 3em 4em"); // fails, left as 1px 2px 3px 4px

  document.body.style[prop] = "1mm";
  t.strictEqual(document.body.style[prop], "1mm");
  t.strictEqual(document.body.style[prop + "Top"], "1mm");
  t.strictEqual(document.body.style[prop + "Right"], "1mm");
  t.strictEqual(document.body.style[prop + "Bottom"], "1mm");
  t.strictEqual(document.body.style[prop + "Left"], "1mm");

  document.body.style[prop] = "1% 2%";
  t.strictEqual(document.body.style[prop], "1% 2%");
  t.strictEqual(document.body.style[prop + "Top"], "1%");
  t.strictEqual(document.body.style[prop + "Right"], "2%");
  t.strictEqual(document.body.style[prop + "Bottom"], "1%");
  t.strictEqual(document.body.style[prop + "Left"], "2%");

  document.body.style[prop] = "3pc 2pc 1pc";
  t.strictEqual(document.body.style[prop], "3pc 2pc 1pc");
  t.strictEqual(document.body.style[prop + "Top"], "3pc");
  t.strictEqual(document.body.style[prop + "Right"], "2pc");
  t.strictEqual(document.body.style[prop + "Bottom"], "1pc");
  t.strictEqual(document.body.style[prop + "Left"], "2pc");
}

t.done();
domenic commented 8 years ago

/cc @dpvc

dpvc commented 8 years ago

I've made a pull request that should resolve the issue.

chad3814 commented 8 years ago

pulling and running jsdom tests now, I've merged and published @dpvc's commit, so this should be good.

chad3814 commented 8 years ago

fixed on 0.2.33