Permalink
Browse files

Added animation example using Sinon fake timers

  • Loading branch information...
1 parent 7df7ced commit cff6d7c4e1c393576aef1bc42a1529f8878653e9 @froots committed Apr 25, 2011
Showing with 28 additions and 4 deletions.
  1. +2 −2 public/javascripts/views/TodoView.js
  2. +26 −2 spec/javascripts/views/TodoView.spec.js
@@ -17,8 +17,8 @@ var TodoView = Backbone.View.extend({
},
edit: function() {
- this.$('h2').hide();
- this.$('input.edit').show();
+ this.$('h2').fadeOut(500);
+ this.$('input.edit').fadeIn(500);
}
});
@@ -69,7 +69,7 @@ describe("TodoView", function() {
});
it("has a done class", function() {
- expect($(this.view.el).find('a')).toHaveClass("done");
+ expect($(this.view.el).find('a:first-child')).toHaveClass("done");
});
});
@@ -78,14 +78,38 @@ describe("TodoView", function() {
describe("Edit state", function() {
- describe("When edit button handler fired", function() {
+ xdescribe("When edit button handler fired - Jasmine async", function() {
beforeEach(function() {
$('ul.todos').append(this.view.render().el);
this.li = $('ul.todos li:first');
this.li.find('a.edit').trigger('click');
});
+ it("shows the edit input field", function() {
+ waits(510);
+ runs(function() {
+ expect(this.li.find('input.edit')).toBeVisible();
+ expect(this.li.find('h2')).not.toBeVisible();
+ })
+ });
+
+ });
+
+ describe("When edit button handler fired - sinon timers", function() {
+
+ beforeEach(function() {
+ this.clock = sinon.useFakeTimers();
+ $('ul.todos').append(this.view.render().el);
+ this.li = $('ul.todos li:first');
+ this.li.find('a.edit').trigger('click');
+ this.clock.tick(600);
+ });
+
+ afterEach(function() {
+ this.clock.restore();
+ });
+
it("shows the edit input field", function() {
expect(this.li.find('input.edit')).toBeVisible();
expect(this.li.find('h2')).not.toBeVisible();

0 comments on commit cff6d7c

Please sign in to comment.