Your SlideShare is downloading. ×
Testing Backbone applications with Jasmine
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Testing Backbone applications with Jasmine

496

Published on

A (very) brief introduction to Jasmine and how to apply it to Backbone applications.

A (very) brief introduction to Jasmine and how to apply it to Backbone applications.

Published in: Software
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
496
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Testing Backbone applications with Jasmine Leon van der Grient 2014
  • 2. You know you should
  • 3. Why? Confidence
  • 4. What? Unitsbehavior
  • 5. When? BeforeDuringAfter
  • 6. How? • qUnit • SinonJS • Mocha • Jasmine
  • 7. Behavior Driven Testing "Users should be able to like a message"
  • 8. Test suite | * Spec | * Expectations
  • 9. describe("Users should be able to", function () { // Your specs });
  • 10. describe("Users should be able to", function () { it("like a message", function () { var a = 1; var b = 2; var c = a + b; expect(c).toEqual(3); expect(c).not.toEqual(4); }); });
  • 11. Spies and mocks spyOn($, "ajax"); $.ajax(arg); ! expect($).toHaveBeenCalled(); expect($).toHaveBeenCalledWith(arg); expect($.calls.count()).toEqual(1);
  • 12. But there is more! spyOn($, "ajax").and.callFake(function () { // mock ajax call var response = { success: true, data: {...} }; arguments[0].success(response); });
  • 13. Models Collections Views
  • 14. Testing models it("like a message", function () { this.message.set({liked:false}); this.message.like(); expect(this.message.get('liked').toBeTruthy(); });
  • 15. Testing views it("like a message", function () { this.message.set({liked:false}); this.view.likeMessage(); expect(this.message.get('liked').toBeTruthy(); });
  • 16. Using mocks spyOn($, "ajax").and.callFake(function () { // mock ajax call var response = { success: true, data: {...} }; arguments[0].success(response); });
  • 17. Test for triggers it("like a message", function () { var spy = jasmine.createSpy(); this.view.listenTo(this.model, "change", spy); this.view.likeMessage(); expect(spy).toHaveBeenCalled(); });
  • 18. Test user interaction with jasmine-jquery plugin it("follow a user", function () { var followBtn = $('.follow-btn'); followBtn.click(); expect(followBtn).toHaveClass("unfollow"); });
  • 19. (too) many tests toBeInDOM() toBeVisible() toHaveAttr() toHaveClass() toHaveText() toHaveValue() toBeChecked() toBeDisabled()
  • 20. Results
  • 21. Again, what? • Methods • The el property • Events • ...?

×