Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Async testing pattern. Better way?
class App.Components.Select extends Backbone.View
initialize: ->
@labelField = @options.labelField
@valueField = @options.valueField
@collection.bind("reset", => @render)
render: ->
options = (item) =>
value: item.get(@valueField)
label: item.get(@labelField)
@$el.html(@template(options: options))
return this
describe App.Components.Select, ->
models = [{ foo: "value1", bar: "label1" }, { foo: "value2", bar: "label2" }]
# simulate async data loading
class collectionClass extends Backbone.Collection
sync: (method, model, options) ->
assert.equal(method, "read")
_.defer options.success, models
beforeEach ->
@collection = new collectionClass
@select = new App.Components.Select
collection: @collection
valueField: "foo"
labelField: "bar"
it "indicates a loading status", ->
context "once the collection has loaded", ->
beforeEach (done) ->
@collection.fetch success: -> done()
it "renders the select options", ->
html = @select.render().$el.find("select option")
options = html, (option) -> { foo: option.value, bar: option.text }
{{#if options}}
{{#each options}}
<option value="{{value}}">{{label}}</option>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.