Skip to content

Commit

Permalink
tests for handlers #65
Browse files Browse the repository at this point in the history
  • Loading branch information
delambo committed Feb 6, 2013
1 parent f6eb65d commit c31fabb
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
43 changes: 43 additions & 0 deletions test/addHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
$(document).ready(function() {

module("Backbone.Stickit");

test('addHandler', function() {

Backbone.Stickit.addHandler({
selector: 'input.trim',
update: function($el, val) { $el.val($.trim(val)); }
});

equal(_.last(Backbone.Stickit._handlers).selector, 'input.trim');

Backbone.Stickit.addHandler([{
selector: 'textarea',
update: function($el, val) { $el.val('blood ' + val); }
}, {
selector: 'div',
updateMethod: 'html'
}]);

equal(_.last(Backbone.Stickit._handlers).selector, 'div');
equal(_.last(Backbone.Stickit._handlers, 2)[0].selector, 'textarea');

model.set({'input':' clot ', 'textarea':'clot', 'div':'<em>clot</em>'});
view.model = model;
view.templateId = 'jst20';
view.bindings = {
'.input': 'input',
'input.trim': 'input',
'#textarea': 'textarea',
'#div': 'div'
};
$('#qunit-fixture').html(view.render().el);

equal(view.$('.input').val(), ' clot ');
equal(view.$('input.trim').val(), 'clot');
equal(view.$('#textarea').val(), 'blood clot');
equal(view.$('#div').text(), 'clot');

Backbone.Stickit._handlers = _.first(Backbone.Stickit._handlers, Backbone.Stickit._handlers.length - 3);
});
});
14 changes: 11 additions & 3 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

<link rel="stylesheet" href="vendor/qunit.css" type="text/css"/>

<script type="text/javascript" src="vendor/zepto.js"></script>
<script type="text/javascript" src="vendor/zepto-data.js"></script>
<!--script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script-->
<!--script type="text/javascript" src="vendor/zepto.js"></script>
<script type="text/javascript" src="vendor/zepto-data.js"></script-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="vendor/qunit.js"></script>
<script type="text/javascript" src="vendor/underscore.js"></script>
<script type="text/javascript" src="vendor/backbone.js"></script>
Expand All @@ -17,6 +17,7 @@
<script type="text/javascript" src="testScaffolding.js"></script>
<script type="text/javascript" src="bindData.js"></script>
<script type="text/javascript" src="modelBinding.js"></script>
<script type="text/javascript" src="addHandler.js"></script>
</head>

<body>
Expand Down Expand Up @@ -104,6 +105,13 @@ <h2 id="qunit-userAgent"></h2>
<input type="checkbox" class="box" value="fountain">
</script>

<script id="jst20" type="text/jst">
<input class='trim'>
<input class='input'>
<textarea id="textarea"></textarea>
<div id="div"></div>
</script>

</body>

</html>

0 comments on commit c31fabb

Please sign in to comment.