Created
November 4, 2011 16:11
-
-
Save searls/1339717 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "CallListView", -> | |
beforeEach -> | |
$template = inject('<script id="call-list-template" type="text/html"></script>') | |
$template.html('HTML <b>for</b> <%= foo %>') | |
@model = jasmine.createSpyObj('CallList',['bind','moveUp','toJSON']) | |
@subject = new CallListView model: @model | |
describe "events", -> | |
it "binds to up-arrow clicks", -> | |
expect(@subject.events).toEqual "click .up-arrow": 'moveUp' | |
describe "#moveUp", -> | |
beforeEach -> | |
$upArrow = $(@subject.el).inject('up-arrow').text('C') | |
@subject.moveUp target: $upArrow[0] | |
it "tells the model to move up the arrow's text", -> | |
expect(@model.moveUp).toHaveBeenCalledWith 'C' | |
describe "#render", -> | |
beforeEach -> | |
@model.toJSON.andReturn foo: "bar" | |
@subject.render() | |
it "renders the template with the model's JSON", -> | |
expect($(@subject.el)).toHaveHtml('HTML <b>for</b> bar') |
This file contains hidden or 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 CallListView extends Backbone.View | |
events: | |
"click .up-arrow": "moveUp" | |
initialize: -> | |
@template = _.template($('#call-list-template').html()) | |
moveUp: (e) -> | |
@model.moveUp $(e.target).text() | |
render: -> | |
$(@el).html(@template(@model.toJSON())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment