Helps
“Adding a JS alert box (with
remote:true, confirm: 'Are you sure?'on alink_to) causes the cucumber feature to fail. It looks like, after we accept the alert withpage.page.driver.browser.switch_to.alert.accept, the browser runs much slower than the cucumber feature, so while everything technically works, the feature fails. We worked around this by delaying cucumber withpage.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 asbeforeSend(which is passed by Rails’remote: true). There must be a better way?”
- One suggestion was to use something like RSpec’s
hash_including, or building it if it doesn’t exist. Turns out, there’s a pull request from earlier this year with just this improvement.
Interestings
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.
Events
- GOV Camp at Suntec City TODAY, November 18, 2-10pm
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.
November 18, 2011 at 2:34 am
Don’t bother stubbing `$.ajax`.
Just use https://github.com/pivotal/jasmine-ajax and write spec like so:
data = JSON.parse(mostRecentAjaxRequest().params)
expect(data.yourStuff).toBe(“YourStuff”)
The `mostRecentAjaxRequest()` returns the full XHR object so you can any type of assertions on it.
Here’s one more example: http://dev.approache.com/testing-your-javascript/#slide21
Cheers.
November 20, 2011 at 9:29 pm