[LRUG] Best practises for jasmine-jquery testing of rails views

Sam Joseph tansaku at gmail.com
Mon Jul 22 12:25:48 PDT 2013


Hi LRUGers,

A couple of questions relating to best practises for jasmine-jquery testing of rails views:

1) what is the "jasmine-ish" best practice for testing code that relies on inspecting or modifying specific page-level elements?  is it to load the required elements as fixtures (i'm using jasmine-jquery) and make sure the code under test is self-contained enough that it doesn't rely on chunks of the page outside of what can be reasonably fixtured?  or is it to insert the elements into the "real" page by sticking them in div#jasmine-content or something like that in a beforeEach?

2) similarly: if i have N distinct pages in my app and each has its own quite distinct JS bits, given that the best practice is to combine all the JS and load it all at once and cache it (asset pipeline), is there a best practice for 'inhibiting' setup functions ($(document).ready()) that don't correspond to the 'current' page?  (ie, your setup function might be trying to bind the '#foo' element, but that element only exists on a particular page; do you let the setup function silently fail, or do you arrange to only run that particular setup function if you're on the page containing #foo, or do you condition the function so that it gracefuly fails in the absence of #foo?)

Many thanks in advance
CHEERS> SAM

-- 
Technical blog: http://linklens.blogspot.com




More information about the Chat mailing list