jejacks0n / teaspoon

Teaspoon: Javascript test runner for Rails. Use Selenium, BrowserStack, or PhantomJS.
1.43k stars 243 forks source link

Support $.parseHtml for more robust fixtures #389

Closed mikepack closed 9 years ago

mikepack commented 9 years ago

Support broken HTML with $.parseHtml. Can't really write a good test for this since Teaspoon doesn't ship with jQuery, but here is the test I built against, which fails without jQuery:

it "supports invalid HTML", ->
  fixture.set("<td>Row</td>")
  expect(document.getElementById("teaspoon-fixtures").innerHTML).toBe("<td>Row</td>")

Fixes #387 Fixes #382

mikepack commented 9 years ago

@jejacks0n :eyes: :pray:

jejacks0n commented 9 years ago

I think jquery is available to our repo through jquery-rails, fwiw. So I think a spec is possible.

jejacks0n commented 9 years ago

Code looks good. I'm a bit skeptical that it's a good change though. Like, can I now make an invalid fixture, get a passing spec, and get different results in the real world if I used .insert or .html?

This was my struggle with the issue. I guess we'll find out. :)

mikepack commented 9 years ago

Yeah, I'm struggling with that as well. It seems like a bad way of using fixtures, unless I'm misunderstanding the use case. Pulling JS down through a fixture seems poor for performance (because of script download/parse blocking), in the case of #387. Testing just the contents of an invalid element, without caring about the surrounding elements that make it valid, also seems like a bad idea and the tests should be moved to a higher level where it's tested against something valid, in the case of #382.

¯\_(ツ)_/¯