Skip to content

Instantly share code, notes, and snippets.

@huafu
Created February 8, 2014 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huafu/8886795 to your computer and use it in GitHub Desktop.
Save huafu/8886795 to your computer and use it in GitHub Desktop.
Example of usit CoffeeScript abstraction library for EmberJS testing with QUnit
###*
Integration test module my composite stats show
###
class Test.MyCompositeStatsShowTest extends IntegrationTestSuite
# URL to load for ALL our tests
url: '/'
# Ajax mock groups to be used
ajaxMockGroupNames: ['basic']
# simple test with only one Ember run loop
test_show_basic: ->
@assertSame find('#some-element').length, 1, "the my composite stats show element should be present"
# Advanced test with many Ember run loop. Each run loop will wait that the bindings are resolved and that there is no
# more stuff waiting or running
# The first argument of each run loop (called here `mb`) is a message bus object which you can use to pass stuff from
# one run loop to another. Here are its predefined properties:
# - `mb.arguments` contains the arguments the test has received
# - `mb.previousResult` contains the result of the previous run loop
# - `mb.merge(object1, object@, ...)` can be used to add multiple property to the message bus object at once
# - `mb.extract('prop1 prop2 prop3')` (or `mb.extract('prop1', 'prop2', 'prop3')`) can be used to extract some
# properties of the message bus object as another object
# If a string is given instead of a function, it'll be interpreted as an URL to visit. The string can also begin with '@'
# in which case the URL will be read from the given property of this test suite
test_show_advanced: [
# first run loop
(mb) ->
mb.controller = controller('myController')
mb.controller.send 'someAction'
# second run loop
(mb) ->
@assertTrue find('#some-element').hasClass('someClass'), "the element should have the correct class"
@assertSame mb.controller.get('length'), 10, "there should be 10 items after someAction"
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment