Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

[Standup][SG] 2011-11-17 – Chock-full of JavaScript


“Adding a JS alert box (with remote:true, confirm: 'Are you sure?' on a link_to) causes the cucumber feature to fail. It looks like, after we accept the alert with, the browser runs much slower than the cucumber feature, so while everything technically works, the feature fails. We worked around this by delaying cucumber with page.should have_no_content('content inside removed li') but it feels like a hack. Does anyone know what could be wrong with our setup, or is this to be expected?”

  • There were no comments other than the work-around we’re already using.

“The pattern we use when testing ajax calls in Jasmine feels unsatisfactory because expect($.ajax).toHaveBeenCalledWith({ /* all params here */}); requires all the parameters passed to the ajax call to be specified in the expectation. This includes parameters we don’t care about, such as beforeSend (which is passed by Rails’ remote: true). There must be a better way?”


  • To get the html of an element (ie: a ‘ul’) including itself, append the element to a new element (ie: an empty div), then get the html of the new element. For example: $('<div>').append($('ul')).html(). The element’s parent could also be used if the element is an only child.

  • When appending an element which already exists in the DOM to another element, it will be moved from its present location in the DOM. This can be problematic when using the trick above to generate an element’s html, and is fixed by cloning the element.

  • If you see ‘Timezone Displacement out of range’ when doing a heroku db:push, it’s probably because you’re using Ruby 1.9.3 in development while Heroku runs 1.9.2. Don’t do that.


  • GOV Camp at Suntec City TODAY, November 18, 2-10pm

  1. Brennan Falkner says:

    function($node) {
    var node = $node[0];

    var attrs = “”;
    for (var i=0;i < node.attributes.length;i++) { var attr = node.attributes.item(i); attrs += " " + attr.nodeName + '="' + attr.nodeValue + '"'; } return "<" + node.nodeName + attrs + ">” + node.innerHTML + ““;

    Generally creating things in order to do a read would be considered a hack.

  2. Don’t bother stubbing `$.ajax`.
    Just use and write spec like so:

    data = JSON.parse(mostRecentAjaxRequest().params)

    The `mostRecentAjaxRequest()` returns the full XHR object so you can any type of assertions on it.

    Here’s one more example:


Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *