Your SlideShare is downloading. ×
0
Unit Testing Framework for JavaScript              Alok Guha
Why Unit Testing ?• Instant satisfaction• Code Against Your API While or Before it is  Built• Leads to a Better Design• Un...
Why UTs are more important with              JavaScript• Because its weak-typed language• Works on client side.• Faster to...
Jasmine      A BDD framework for JavaScript testing• a behavior-driven development framework for  testing JavaScript code....
Suits & Spects
Expectations & Matchers• To express what you expect about behavior of  your code.• Matcher implements a Boolean comparison...
Frequently Used Matchers•   The toBe matcher compares with ===•   The toEqual matcher•   The toMatch matcher is for regula...
beforeEach & afterEach• Both takes a function which executes before  and after execution of each spec.
Spy• These are mock or fake calls to method.• Spies should be created before expectations.• Spies can be checked if they w...
Think Tests ?
Possible Test cases• a & b should be defined always.• If a & b defined it should return sum of them.• if a or b is not def...
Lets welcome Jasmine• Live examples
references•   http://pivotal.github.com/jasmine/•   http://evanhahn.com/how-do-i-jasmine/•   http://try-jasmine.heroku.com...
Jasmine
Jasmine
Upcoming SlideShare
Loading in...5
×

Jasmine

415

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
415
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Where to start in the processWhat to test and what not to testHow much to test in one goWhat to call the testsHow to understand why a test failsdefine a test set for the unit first;then implement the unit;finally verify that the implementation of the unit makes the tests succeed.
  • Transcript of "Jasmine"

    1. 1. Unit Testing Framework for JavaScript Alok Guha
    2. 2. Why Unit Testing ?• Instant satisfaction• Code Against Your API While or Before it is Built• Leads to a Better Design• Understand How Your Code Works• Confidence in Your Code
    3. 3. Why UTs are more important with JavaScript• Because its weak-typed language• Works on client side.• Faster to test Unit Tests than to browse actual application.
    4. 4. Jasmine A BDD framework for JavaScript testing• a behavior-driven development framework for testing JavaScript code.• does not depend on any other JavaScript frameworks• does not require DOM.• Can be integrated with any CI tool.
    5. 5. Suits & Spects
    6. 6. Expectations & Matchers• To express what you expect about behavior of your code.• Matcher implements a Boolean comparison between the actual value and the expected value
    7. 7. Frequently Used Matchers• The toBe matcher compares with ===• The toEqual matcher• The toMatch matcher is for regular expressions• The toBeDefined matcher compares against `undefined`• The `toBeUndefined` matcher compares against `undefined`• The toBeNull matcher compares against null• The toBeTruthy matcher is for boolean casting testing• The toBeFalsy matcher is for boolean casting testing• The toContain matcher is for finding an item in an ArrayEvery matcher’s criteria can be inverted by prepending .not
    8. 8. beforeEach & afterEach• Both takes a function which executes before and after execution of each spec.
    9. 9. Spy• These are mock or fake calls to method.• Spies should be created before expectations.• Spies can be checked if they were called or not, and what was calling arguments.
    10. 10. Think Tests ?
    11. 11. Possible Test cases• a & b should be defined always.• If a & b defined it should return sum of them.• if a or b is not defined, result should be undefined.• Result should be in same cast as input provided.
    12. 12. Lets welcome Jasmine• Live examples
    13. 13. references• http://pivotal.github.com/jasmine/• http://evanhahn.com/how-do-i-jasmine/• http://try-jasmine.heroku.com/• My own experiences.
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×