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

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 

Recently uploaded (20)

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 

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