SlideShare a Scribd company logo
1 of 18
Testeando JavaScript con
        Jasmine




                   Por: Rodrigo Quelca
Que es Jasmine?


Jasmine es un Framework de
   pruebas unitarias para
        JavaScript.
Introducion.js
Caracteristicas


Jasmine es un Framework de
   pruebas unitarias para
        JavaScript.
Estructura.js

  describe("A suite", function() {
    var a=4; //javascript code
    it("contains spec with an expectation", function() {
      expect(true).toBe(true);
    });
  });



                      Suites: describe Your Tests
                       Specs
ejemplo.js
 HelloWorld.js

  function helloWorld() {
      return "Hello world!";
  }



                       spec/HelloWorld.js

          describe("Hello world", function() {
              it("says hello", function() {
                  expect(helloWorld()).toEqual("Hello world!");
              });
          });
ejemplo.js
      SpecRunner.html

   function helloWorld() {
       return "Hello world!";
   }
 <link rel="stylesheet" type="text/css" href="../jasmine.css">

 <script type="text/javascript" src="../jasmine.js"></script>
 <script type="text/javascript" src="../jasmine-html.js"></script>

 <!-- include spec files here... -->
 <script type="text/javascript" src="spec/HelloWorldSpec.js"></script>

 <!-- include source files here... -->
 <script type="text/javascript" src="src/HelloWorld.js"></script>
Algunos Comparadores
   expect(x).toEqual(y)
   expect(x).toBe(y);
   expect(x).toMatch(pattern); //regexp
   expect(x).toBeDefined();
   expect(x).toBeNull();
   expect(x).toBeTruthy();
   expect(x).toBeFalsy();
   expect(x).toContain(y);
   expect(x).toBeLessThan(y);
   expect(x).toBeGreaterThan(y);
   expect(fn).toThrow(e);

   expect(x).not.toEqual(y)
Comparadores personalizados
   describe('Hello world', function() {


         beforeEach(function() {
             this.addMatchers({
                 toBeDivisibleByTwo: function() {
                   return (this.actual % 2) === 0;
                 }
             });
         });


         it('is divisible by 2', function() {
             expect(gimmeANumber()).toBeDivisibleByTwo();
         });


   });
Before y after
   describe("A spec (with setup and tear-down)", function() {
       var foo;
       beforeEach(function() {
           foo = 0;
           foo += 1;
       });
       afterEach(function() {
           foo = 0;
       });
       it("is just a function, so it can contain any code", function() {
           expect(foo).toEqual(1);
       });
       it("can have more than one expectation", function() {
           expect(foo).toEqual(1);
           expect(true).toEqual(true);
       });
   });
Spies
 var Person = function() {};

 Person.prototype.helloSomeone = function(toGreet) {
    return this.sayHello() + " " + toGreet;
 };

 Person.prototype.sayHello = function() {
    return "Hello";
 };



                     describe("Person", function() {
                         it("calls the sayHello() function", function() {
                             var fakePerson = new Person();
                             spyOn(fakePerson, "sayHello");
                             fakePerson.helloSomeone("world");
                             expect(fakePerson.sayHello).toHaveBeenCalled();
                         });
                     });
Creando Spies
 var Person = function() {};

 Person.prototype.helloSomeone = function(toGreet) {
    return this.sayHello() + " " + toGreet;
 };

 Person.prototype.sayHello = function() {
    return "Hello";
 };



                  describe("Person", function() {
                      it("says hello", function() {
                          var fakePerson = new Person();
                          fakePerson.sayHello = jasmine.createSpy("Say-hello spy");
                          fakePerson.helloSomeone("world");
                          expect(fakePerson.sayHello).toHaveBeenCalled();
                      });
                  });
Tests asincronos(run(),waitsFor())

 describe("Calculator", function() {
     it("should factor two huge numbers asynchronously", function() {
         var calc = new Calculator();
         var answer = calc.factor(18973547201226, 28460320801839);
         expect(answer).toEqual(9486773600613); // DANGER ZONE:
 This doesn't work if factor() is asynchronous!!
         // THIS DOESN'T WORK, STUPID
     });
 });
Tests asincronos(run(),waitsFor())
describe("Calculator", function() {
    it("should factor two huge numbers asynchronously", function() {
        var calc = new Calculator();
        var answer = calc.factor(18973547201226, 28460320801839);
        waitsFor(function() {
            return calc.answerHasBeenCalculated();
        }, "It took too long to find those factors.", 10000);
        runs(function() {
            expect(answer).toEqual(9486773600613);
        });
    });
});
Tests jQuery
describe('I add a ToDo', function () {
 var mocks = {};
 beforeEach(function () {
   loadFixtures("index.html");
   mocks.todo = "something fun";
   $('#todo').val(mocks.todo);
   ToDo.setup();
 });
 it('should call the addToDo function when create is clicked', function () {
   spyOn(ToDo, 'addToDo');
   $('#create').click();
   expect(ToDo.addToDo).toHaveBeenCalledWith(mocks.todo);
 });

});
Referencias
 Pivotal Labs pagina oficial
 http://pivotal.github.com/jasmine/

 How do I Jasmine
 http://evanhahn.com/?p=181

 jasmine-jquery
 https://github.com/velesin/jasmine-jquery/

 Testing jQuery plugins with Node.js and Jasmine
 http://digitalbush.com/2011/03/29/testing-jquery-plugins-
 with-node-js-and-jasmine/

 Tests de JavaScript con Jasmine
 http://es.asciicasts.com/episodes/261-tests-de-
 javascript-con-jasmine
Manos a la obra ...
Gracias ...

More Related Content

What's hot

for this particular program how do i create the input innotepad 1st ? #includ...
for this particular program how do i create the input innotepad 1st ? #includ...for this particular program how do i create the input innotepad 1st ? #includ...
for this particular program how do i create the input innotepad 1st ? #includ...
hwbloom59
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bits
Chris Saylor
 

What's hot (17)

Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testing
 
Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8
 
meet.js - QooXDoo
meet.js - QooXDoomeet.js - QooXDoo
meet.js - QooXDoo
 
Practical JavaScript Programming - Session 5/8
Practical JavaScript Programming - Session 5/8Practical JavaScript Programming - Session 5/8
Practical JavaScript Programming - Session 5/8
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the AST
 
NoSQL Injections in Node.js - The case of MongoDB
NoSQL Injections in Node.js - The case of MongoDBNoSQL Injections in Node.js - The case of MongoDB
NoSQL Injections in Node.js - The case of MongoDB
 
for this particular program how do i create the input innotepad 1st ? #includ...
for this particular program how do i create the input innotepad 1st ? #includ...for this particular program how do i create the input innotepad 1st ? #includ...
for this particular program how do i create the input innotepad 1st ? #includ...
 
Nantes Jug - Java 7
Nantes Jug - Java 7Nantes Jug - Java 7
Nantes Jug - Java 7
 
Devoxx 2012 hibernate envers
Devoxx 2012   hibernate enversDevoxx 2012   hibernate envers
Devoxx 2012 hibernate envers
 
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
 
for this particular program how do i create the input innotepad 1st ?#include...
for this particular program how do i create the input innotepad 1st ?#include...for this particular program how do i create the input innotepad 1st ?#include...
for this particular program how do i create the input innotepad 1st ?#include...
 
Security Challenges in Node.js
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.js
 
ES2015 workflows
ES2015 workflowsES2015 workflows
ES2015 workflows
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bits
 
Ruby - Design patterns tdc2011
Ruby - Design patterns tdc2011Ruby - Design patterns tdc2011
Ruby - Design patterns tdc2011
 
Nodejs do teste de unidade ao de integração
Nodejs  do teste de unidade ao de integraçãoNodejs  do teste de unidade ao de integração
Nodejs do teste de unidade ao de integração
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com Backbone
 

Viewers also liked

ITM ALUMNI Meet 2012
ITM ALUMNI Meet 2012ITM ALUMNI Meet 2012
ITM ALUMNI Meet 2012
Rajan Gupta
 
Arrows Group Brochure (Technology)
Arrows Group Brochure (Technology)Arrows Group Brochure (Technology)
Arrows Group Brochure (Technology)
B20wna
 
Bahasan 7 teknologi website
Bahasan 7 teknologi websiteBahasan 7 teknologi website
Bahasan 7 teknologi website
fifirahmi
 

Viewers also liked (19)

Aux confins du nord vietnam
Aux confins du nord vietnamAux confins du nord vietnam
Aux confins du nord vietnam
 
Acoustic Duet
Acoustic Duet Acoustic Duet
Acoustic Duet
 
Проект
ПроектПроект
Проект
 
¿Sabes cómo gestionar tu información en la era digital?
¿Sabes cómo gestionar tu información en la era digital?¿Sabes cómo gestionar tu información en la era digital?
¿Sabes cómo gestionar tu información en la era digital?
 
Pdhpe Power Point
Pdhpe Power PointPdhpe Power Point
Pdhpe Power Point
 
Notes on validation
Notes on validationNotes on validation
Notes on validation
 
所有Windows store 市集相關faq
所有Windows store 市集相關faq所有Windows store 市集相關faq
所有Windows store 市集相關faq
 
Social engineeringpresentation
Social engineeringpresentationSocial engineeringpresentation
Social engineeringpresentation
 
Katie\'s Portfolio
Katie\'s PortfolioKatie\'s Portfolio
Katie\'s Portfolio
 
ITM ALUMNI Meet 2012
ITM ALUMNI Meet 2012ITM ALUMNI Meet 2012
ITM ALUMNI Meet 2012
 
A wise camel
A wise camelA wise camel
A wise camel
 
Entornos virtuales
Entornos virtualesEntornos virtuales
Entornos virtuales
 
Arrows Group Brochure (Technology)
Arrows Group Brochure (Technology)Arrows Group Brochure (Technology)
Arrows Group Brochure (Technology)
 
Prezi
PreziPrezi
Prezi
 
Linked Data and Public Administration
Linked Data and Public AdministrationLinked Data and Public Administration
Linked Data and Public Administration
 
As media studies task
As media studies taskAs media studies task
As media studies task
 
Uintah Basin Energy and Transportation Study
Uintah Basin Energy and Transportation StudyUintah Basin Energy and Transportation Study
Uintah Basin Energy and Transportation Study
 
Bahasan 7 teknologi website
Bahasan 7 teknologi websiteBahasan 7 teknologi website
Bahasan 7 teknologi website
 
Meeting minutes 8
Meeting minutes 8Meeting minutes 8
Meeting minutes 8
 

Similar to Introduccion a Jasmin

JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
whitneyleman54422
 

Similar to Introduccion a Jasmin (20)

JavaScript Unit Testing with Jasmine
JavaScript Unit Testing with JasmineJavaScript Unit Testing with Jasmine
JavaScript Unit Testing with Jasmine
 
Stop Making Excuses and Start Testing Your JavaScript
Stop Making Excuses and Start Testing Your JavaScriptStop Making Excuses and Start Testing Your JavaScript
Stop Making Excuses and Start Testing Your JavaScript
 
Jasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishyJasmine - why JS tests don't smell fishy
Jasmine - why JS tests don't smell fishy
 
Jasmine BDD for Javascript
Jasmine BDD for JavascriptJasmine BDD for Javascript
Jasmine BDD for Javascript
 
AngularJS Testing
AngularJS TestingAngularJS Testing
AngularJS Testing
 
04 Advanced Javascript
04 Advanced Javascript04 Advanced Javascript
04 Advanced Javascript
 
Javascript - Beyond-jQuery
Javascript - Beyond-jQueryJavascript - Beyond-jQuery
Javascript - Beyond-jQuery
 
Java 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR BeneluxJava 8 - Nuts and Bold - SFEIR Benelux
Java 8 - Nuts and Bold - SFEIR Benelux
 
JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
How to test complex SaaS applications - The family july 2014
How to test complex SaaS applications - The family july 2014How to test complex SaaS applications - The family july 2014
How to test complex SaaS applications - The family july 2014
 
JavaScript patterns
JavaScript patternsJavaScript patterns
JavaScript patterns
 
2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript
 
2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
 
Object-oriented Javascript
Object-oriented JavascriptObject-oriented Javascript
Object-oriented Javascript
 
Say It With Javascript
Say It With JavascriptSay It With Javascript
Say It With Javascript
 
AngularJS Testing Strategies
AngularJS Testing StrategiesAngularJS Testing Strategies
AngularJS Testing Strategies
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
 
ES2015 New Features
ES2015 New FeaturesES2015 New Features
ES2015 New Features
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

Introduccion a Jasmin

  • 1. Testeando JavaScript con Jasmine Por: Rodrigo Quelca
  • 2. Que es Jasmine? Jasmine es un Framework de pruebas unitarias para JavaScript.
  • 4. Caracteristicas Jasmine es un Framework de pruebas unitarias para JavaScript.
  • 5. Estructura.js describe("A suite", function() { var a=4; //javascript code it("contains spec with an expectation", function() { expect(true).toBe(true); }); }); Suites: describe Your Tests Specs
  • 6. ejemplo.js HelloWorld.js function helloWorld() { return "Hello world!"; } spec/HelloWorld.js describe("Hello world", function() { it("says hello", function() { expect(helloWorld()).toEqual("Hello world!"); }); });
  • 7. ejemplo.js SpecRunner.html function helloWorld() { return "Hello world!"; } <link rel="stylesheet" type="text/css" href="../jasmine.css"> <script type="text/javascript" src="../jasmine.js"></script> <script type="text/javascript" src="../jasmine-html.js"></script> <!-- include spec files here... --> <script type="text/javascript" src="spec/HelloWorldSpec.js"></script> <!-- include source files here... --> <script type="text/javascript" src="src/HelloWorld.js"></script>
  • 8. Algunos Comparadores expect(x).toEqual(y) expect(x).toBe(y); expect(x).toMatch(pattern); //regexp expect(x).toBeDefined(); expect(x).toBeNull(); expect(x).toBeTruthy(); expect(x).toBeFalsy(); expect(x).toContain(y); expect(x).toBeLessThan(y); expect(x).toBeGreaterThan(y); expect(fn).toThrow(e); expect(x).not.toEqual(y)
  • 9. Comparadores personalizados describe('Hello world', function() { beforeEach(function() { this.addMatchers({ toBeDivisibleByTwo: function() { return (this.actual % 2) === 0; } }); }); it('is divisible by 2', function() { expect(gimmeANumber()).toBeDivisibleByTwo(); }); });
  • 10. Before y after describe("A spec (with setup and tear-down)", function() { var foo; beforeEach(function() { foo = 0; foo += 1; }); afterEach(function() { foo = 0; }); it("is just a function, so it can contain any code", function() { expect(foo).toEqual(1); }); it("can have more than one expectation", function() { expect(foo).toEqual(1); expect(true).toEqual(true); }); });
  • 11. Spies var Person = function() {}; Person.prototype.helloSomeone = function(toGreet) { return this.sayHello() + " " + toGreet; }; Person.prototype.sayHello = function() { return "Hello"; }; describe("Person", function() { it("calls the sayHello() function", function() { var fakePerson = new Person(); spyOn(fakePerson, "sayHello"); fakePerson.helloSomeone("world"); expect(fakePerson.sayHello).toHaveBeenCalled(); }); });
  • 12. Creando Spies var Person = function() {}; Person.prototype.helloSomeone = function(toGreet) { return this.sayHello() + " " + toGreet; }; Person.prototype.sayHello = function() { return "Hello"; }; describe("Person", function() { it("says hello", function() { var fakePerson = new Person(); fakePerson.sayHello = jasmine.createSpy("Say-hello spy"); fakePerson.helloSomeone("world"); expect(fakePerson.sayHello).toHaveBeenCalled(); }); });
  • 13. Tests asincronos(run(),waitsFor()) describe("Calculator", function() { it("should factor two huge numbers asynchronously", function() { var calc = new Calculator(); var answer = calc.factor(18973547201226, 28460320801839); expect(answer).toEqual(9486773600613); // DANGER ZONE: This doesn't work if factor() is asynchronous!! // THIS DOESN'T WORK, STUPID }); });
  • 14. Tests asincronos(run(),waitsFor()) describe("Calculator", function() { it("should factor two huge numbers asynchronously", function() { var calc = new Calculator(); var answer = calc.factor(18973547201226, 28460320801839); waitsFor(function() { return calc.answerHasBeenCalculated(); }, "It took too long to find those factors.", 10000); runs(function() { expect(answer).toEqual(9486773600613); }); }); });
  • 15. Tests jQuery describe('I add a ToDo', function () { var mocks = {}; beforeEach(function () { loadFixtures("index.html"); mocks.todo = "something fun"; $('#todo').val(mocks.todo); ToDo.setup(); }); it('should call the addToDo function when create is clicked', function () { spyOn(ToDo, 'addToDo'); $('#create').click(); expect(ToDo.addToDo).toHaveBeenCalledWith(mocks.todo); }); });
  • 16. Referencias Pivotal Labs pagina oficial http://pivotal.github.com/jasmine/ How do I Jasmine http://evanhahn.com/?p=181 jasmine-jquery https://github.com/velesin/jasmine-jquery/ Testing jQuery plugins with Node.js and Jasmine http://digitalbush.com/2011/03/29/testing-jquery-plugins- with-node-js-and-jasmine/ Tests de JavaScript con Jasmine http://es.asciicasts.com/episodes/261-tests-de- javascript-con-jasmine
  • 17. Manos a la obra ...