Created
February 16, 2012 20:23
-
-
Save richball/1847581 to your computer and use it in GitHub Desktop.
Trying to test selection event
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
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 |
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
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I got this passing in this gist:
https://gist.github.com/1885097