Skip to content

Instantly share code, notes, and snippets.

@richball
Created February 16, 2012 20:23
Show Gist options
  • Save richball/1847581 to your computer and use it in GitHub Desktop.
Save richball/1847581 to your computer and use it in GitHub Desktop.
Trying to test selection event
class ContactUs.Views.DataSetControlView extends ContactUs.Views.SerializableView
template: "performance/data-set-control"
id: 'dataset-select'
events:
'change': -> @optionSelected(event)
initialize: ->
@collection.bind "reset", => @render()
serialize: ->
options: @collection.toJSON()
optionSelected: (event) ->
value = $("option:selected", $(event.currentTarget)).val();
ContactUs.Notification.trigger ContactUs.Notification.datasetChanged, value
describe "ContactUs.Views.DataSetControlView", ->
Given -> affix("select#dataset-select option[value=bar]+option[value=foo]")
Given -> @collection = new Backbone.Collection
Given -> @subject = new ContactUs.Views.DataSetControlView collection: @collection
Then -> @subject.template == "performance/data-set-control"
Then -> @subject.id == "dataset-select"
describe "model binding", ->
Given -> spyOn(@subject, 'render')
When -> @collection.reset()
Then -> expect(@subject.render).toHaveBeenCalled()
describe "#serialize", ->
Given -> @collection.add { a : "FOO!"}
When -> @result = @subject.serialize()
Then -> expect(@result).toEqual
options : [
a : 'FOO!'
]
describe "#optionSelected", ->
Given -> spyOn(@subject, 'optionSelected')
When -> $('#dataset-select').val('foo')
Then -> expect(@subject.optionSelected).toHaveBeenCalled()
@searls
Copy link

searls commented Feb 22, 2012

I got this passing in this gist:

https://gist.github.com/1885097

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment