Created
February 28, 2014 16:38
-
-
Save mikepack/9274300 to your computer and use it in GitHub Desktop.
Ember Component Test Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AppTest.setupComponent = (name, content, options, setupCallback=null)-> | |
beforeEach -> | |
Ember.$('<div id="test-container"><div id="test"></div></div>').appendTo('body'); | |
Ember.run -> | |
AppTest.App = Ember.Application.create | |
rootElement: '#test' | |
AppTest.App.Store = DS.Store.extend | |
adapter: DS.FixtureAdapter.extend | |
simulateRemoteResponse: true | |
latency: 200 | |
Ember.TEMPLATES.application = Ember.Handlebars.compile("{{outlet}}") | |
componentOptions = _(options).inject((memo, value, key)-> | |
memo += " #{key}=#{value}" | |
, "") | |
Ember.TEMPLATES.index = Ember.Handlebars.compile "{{#{name}#{componentOptions}}}" | |
AppTest.App["#{name}-component".classify()] = App["#{name}-component".classify()] | |
AppTest.App.IndexController = Ember.ObjectController.extend | |
init: -> | |
@_super(arguments...) | |
@set('content', content) | |
AppTest.App.Router.map(App.Router.router.callbacks[0]) | |
AppTest.App.Router.map -> | |
@route('index', path: '/') | |
setupCallback?.call(@, AppTest.App) | |
AppTest.App.setupForTesting() | |
Ember.run -> | |
AppTest.App.advanceReadiness() | |
AppTest.App.injectTestHelpers() | |
afterEach -> | |
AppTest.App.removeTestHelpers() | |
Ember.$('#test-container, #test').remove() | |
Ember.run(AppTest.App, AppTest.App.destroy) | |
AppTest.App = null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment