jamesshore / quixote

CSS unit and integration testing
Other
848 stars 45 forks source link

Prevent frame.add() from choking on leading/trailing whitespace #28

Closed nwah closed 8 years ago

nwah commented 8 years ago

Hey @jamesshore,

This PR just strips leading / trailing whitespace from html passing into frame.add() before assigning it to tempElement.innerHTML.

I just discovered Quixote and am very excited about it, but when I just tried to write my first test, doing something like this:

frame.add(`
  <div id="container">
    <p id="paragraph">
      This is a paragraph.
    </p>
  </div>
`)

I got this error:

Expected one element, but got 3

It seems like when doing tempElement.innerHTML = html (here), it's creating text nodes with the whitespace, which makes the subsequent check for only 1 childNode fail.

jamesshore commented 8 years ago

Nice catch, thank you.

jamesshore commented 8 years ago

Merged, thank you! This will be in v0.12, releasing momentarily.

jamesshore commented 8 years ago

Surprisingly, the regex you provided failed on IE 11 (but not IE 8 or Edge). I replaced it with String.trim(), plus a shim for IE 8.