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

Workshop 5: JavaScript testing
Workshop 5: JavaScript testingWorkshop 5: JavaScript testing
Workshop 5: JavaScript testingVisual Engineering
 
Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8Wilson Su
 
Practical JavaScript Programming - Session 5/8
Practical JavaScript Programming - Session 5/8Practical JavaScript Programming - Session 5/8
Practical JavaScript Programming - Session 5/8Wilson Su
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the ASTJarrod Overson
 
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 MongoDBSqreen
 
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
 
Devoxx 2012 hibernate envers
Devoxx 2012   hibernate enversDevoxx 2012   hibernate envers
Devoxx 2012 hibernate enversRomain Linsolas
 
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」matuura_core
 
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...hwbloom14
 
Security Challenges in Node.js
Security Challenges in Node.jsSecurity Challenges in Node.js
Security Challenges in Node.jsWebsecurify
 
Javascript: the important bits
Javascript: the important bitsJavascript: the important bits
Javascript: the important bitsChris Saylor
 
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çãoVinícius Pretto da Silva
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneRafael Felix da Silva
 

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

Aux confins du nord vietnam
Aux confins du nord vietnamAux confins du nord vietnam
Aux confins du nord vietnamTheMinHoang
 
¿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?Elizabeth Ontaneda
 
Pdhpe Power Point
Pdhpe Power PointPdhpe Power Point
Pdhpe Power PointSasha Yang
 
Notes on validation
Notes on validationNotes on validation
Notes on validationDhruv Desai
 
Social engineeringpresentation
Social engineeringpresentationSocial engineeringpresentation
Social engineeringpresentationDonna Rougeau
 
Katie\'s Portfolio
Katie\'s PortfolioKatie\'s Portfolio
Katie\'s Portfoliokatiedhahn
 
ITM ALUMNI Meet 2012
ITM ALUMNI Meet 2012ITM ALUMNI Meet 2012
ITM ALUMNI Meet 2012Rajan Gupta
 
Entornos virtuales
Entornos virtualesEntornos virtuales
Entornos virtualesJanrth
 
Arrows Group Brochure (Technology)
Arrows Group Brochure (Technology)Arrows Group Brochure (Technology)
Arrows Group Brochure (Technology)B20wna
 
Linked Data and Public Administration
Linked Data and Public AdministrationLinked Data and Public Administration
Linked Data and Public AdministrationOscar Corcho
 
Bahasan 7 teknologi website
Bahasan 7 teknologi websiteBahasan 7 teknologi website
Bahasan 7 teknologi websitefifirahmi
 

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 Unit Testing with Jasmine
JavaScript Unit Testing with JasmineJavaScript Unit Testing with Jasmine
JavaScript Unit Testing with JasmineRaimonds Simanovskis
 
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 JavaScriptRyan Anklam
 
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 fishyIgor Napierala
 
AngularJS Testing
AngularJS TestingAngularJS Testing
AngularJS TestingEyal Vardi
 
04 Advanced Javascript
04 Advanced Javascript04 Advanced Javascript
04 Advanced Javascriptcrgwbr
 
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 Beneluxyohanbeschi
 
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)Anders Jönsson
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developersStoyan Stefanov
 
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 2014Guillaume POTIER
 
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 JavaScriptJohannes Hoppe
 
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 JavaScriptJohannes Hoppe
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxwhitneyleman54422
 
Object-oriented Javascript
Object-oriented JavascriptObject-oriented Javascript
Object-oriented JavascriptDaniel Ku
 
AngularJS Testing Strategies
AngularJS Testing StrategiesAngularJS Testing Strategies
AngularJS Testing Strategiesnjpst8
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryAlexandre Morgaut
 

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

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
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...DianaGray10
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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 DiscoveryTrustArc
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 

Recently uploaded (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 

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 ...