Skip to content

Commit

Permalink
spec to show failing when input has no type specified
Browse files Browse the repository at this point in the history
  • Loading branch information
Derick Bailey committed Aug 27, 2011
1 parent 15e9587 commit 20a2d9d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions spec/javascripts/helpers/sample.backbone.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ AModel = Backbone.Model.extend({});
AView = Backbone.View.extend({
render: function(){
var html = $("\
<input id='noType'>\
<div id='showHideThing' data-bind='displayed isValid' />\
<div id='showHideAnotherThing' data-bind='hidden isValid' />\
<button id='unclicker' data-bind='disabled isValid'>Click Me!</button>\
Expand Down
53 changes: 53 additions & 0 deletions spec/javascripts/textboxConventionBinding.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
describe("textbox convention bindings", function(){
beforeEach(function(){
this.model = new AModel({
name: "Ashelia Bailey",
noType: 'there is no type'
});
this.view = new AView({model: this.model});
this.view.render();
});

describe("text element binding", function(){
it("bind view changes to the model's field, by convention of id", function(){
var el = this.view.$("#name");
el.val("Derick Bailey");
el.trigger('change');

expect(this.model.get('name')).toEqual("Derick Bailey");
});

it("bind model field changes to the form input, by convention of id", function(){
this.model.set({name: "Ian Bailey"});
var el = this.view.$("#name");
expect(el.val()).toEqual("Ian Bailey");
});

it("binds the model's value to the form field on render", function(){
var el = this.view.$("#name");
expect(el.val()).toEqual("Ashelia Bailey");
});
});

describe("input with no type specified, binding", function(){
beforeEach(function(){
this.el = this.view.$("#noType");
});

it("bind view changes to the model's field, by convention of id", function(){
this.el.val("something changed");
this.el.trigger('change');

expect(this.model.get('noType')).toEqual("something changed");
});

it("bind model field changes to the form input, by convention of id", function(){
this.model.set({noType: "Ian Bailey"});
expect(this.el.val()).toEqual("Ian Bailey");
});

it("binds the model's value to the form field on render", function(){
expect(this.el.val()).toEqual("there is no type");
});
});
});

0 comments on commit 20a2d9d

Please sign in to comment.