Sitemap
John Allison

John Allison

Software Developer, Golfer, Arkansas Razorback fan, founder of http://customer.io. You can find me on the twitters: @jrallison

Playing around with QUnit and Ember.js behavioral testing

2 min readJun 10, 2013

--

We use Ember.js heavily at Customer.io. One problem we’ve faced has been testing the user experience of our ember application in an efficient and automated fashion.

Thankfully, about a month and a half ago at the monthly Ember.js NYC meetup, Erik Bryn gave a talk about recent testing improvements in ember and his work on the ember-testing package.

The ember-testing package essentially provides test helpers which wrap asynchronous portions of ember in promises. We can then use these helpers to reliably interact with the ember application under test.

The major benefit is this allows us to easily test our ember application’s behavior in isolation (when stubbing out our API with ember-data’s fixture adapter).

Press enter or click to view image in full size
An example test with the ember-testing package written in CoffeeScript.

So far, the ember-testing package contains four helpers:

visit(url)
click(selector)
fillIn(selector, text)
find(selector)

As more people use these helpers to test their interface, I expect it to become a lot more full featured. I’m already playing around with a few helpers of my own to contribute back.

Get John Allison’s stories in your inbox

Join Medium for free to get updates from this writer.

Since we’re now running our ember application inside of QUnit, I took a stab yesterday at minimizing QUnit’s testing interface to focus more on a live view of the app.

Here’s how it looks while running through a few tests (heavily influenced by RSpec’s progress format):

To tweak the QUnit output, I used a customized stylesheet to hide all the default reporting and used callbacks to create the new report:

QUnit.config.hidepassed = trueQUnit.log (details) ->
if details.result
$(“#results”).append(“<span class=’pass’>.</span>”)
else
$(“#results”).append(“<span class=’fail’>F</span>”)
QUnit.done (details) ->
if details.passed == details.total
$(“#results”).addClass(“passed”)
else
$(“#results”).addClass(“failed”)
$(“#qunit-tests”).show()
html = [
“Tests completed in “,
details.runtime,
“ milliseconds.<br/>”,
“<span class=’passed’>”,
details.passed,
“</span> tests of <span class=’total’>”,
details.total,
“</span> passed, <span class=’failed’>”,
details.failed,
“</span> failed.”,
].join “”
$(“#results”).append(“<div class=’summary’>” + html)

--

--

John Allison
John Allison

Written by John Allison

Software Developer, Golfer, Arkansas Razorback fan, founder of http://customer.io. You can find me on the twitters: @jrallison