Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added animation example using Sinon fake timers

  • Loading branch information...
commit cff6d7c4e1c393576aef1bc42a1529f8878653e9 1 parent 7df7ced
@froots authored
View
4 public/javascripts/views/TodoView.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);
}
});
View
28 spec/javascripts/views/TodoView.spec.js
@@ -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,7 +78,7 @@ 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);
@@ -87,6 +87,30 @@ describe("TodoView", function() {
});
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();
});
Please sign in to comment.
Something went wrong with that request. Please try again.