SlideServe
Menu
Préférences
© SlideServe · v2026

Alok Guha

zamir avatar
15 diapositives · 329 Views · Jul 20, 2014

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 Understand How Your Code Works Confidence in Your Code. Why UTs are more important with JavaScript.

Alok Guha - slide 1
01 / 15Alok Guha
1 / 17

Télécharger la présentation

Alok Guha
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Unit Testing Framework for JavaScript Alok Guha

  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. 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. JasmineA 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. Suits & Spects

  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. 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 Array Every matcher’s criteria can be inverted by prepending .not

  8. beforeEach & afterEach • Both takes a function which executes before and after execution of each spec.

  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. Think Tests ?

  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. Lets welcome Jasmine • Live examples

  13. references • http://pivotal.github.com/jasmine/ • http://evanhahn.com/how-do-i-jasmine/ • http://try-jasmine.heroku.com/ • My own experiences.