Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Jasmine / Sinon.js Jorge Falcão  Sergio Azevedo [email_address] @sergioazevedo
Jasmine
Jasmine
Jasmine
Jasmine
Jasmine
Jasmine / Spec //# ContaSpec.js # describe ('Conta',  function (){ it ("deve realizar saques",  function (){ var...
Jasmine / Spec describe ('Conta',  function (){ it ("deve realizar saques",  function (){ var  conta =  new  Con...
Jasmine / beforeEach describe('Conta', function() { it("deve realizar saques", function() { var conta = new Cont...
Jasmine / beforeEach describe('Conta', function() { var conta; beforeEach(function() { var conta = new Conta({ saldo: 1000...
Jasmine / Nested Spec describe('Conta', function() { var conta; describe('Conta Sem Bloqueio', function() { beforeEach(fun...
Jasmine / Matchers expect (conta.saldo). toEqual (1000); expect (conta). toBe (conta); expect (conta.titular). toMatch (/a...
Jasmine / Spies describe ('Banco', function (){ it ("deve taxar suas contas",  function (){ var banco = new Banc...
Jasmine / Asynchronous specs describe ("Testes Assicronos",  function ({ it ("exemplo com waits",  fun...
Jasmine / Asynchronous specs
Jasmine / Asynchronous specs describe ("Testes Assicronos",  function ({ it ("exemplo com waits",  fun...
Jasmine / Asynchronous specs describe ("Testes Assicronos",  function ({ it ("exemplo com waits",  fun...
Jasmine / Asynchronous specs
Jasmine / Asynchronous specs it("exemplo com waitsFor", function() { var a = 1; var somado = false; setTimeout(f...
Sinon.JS
Sinon.js <ul><li>Spies </li></ul><ul><li>Stubs </li></ul><ul><li>Mocks </li></ul><ul><li>Fake Timers </li></ul><ul><li>Fak...
Sinon.js
Sinon.js/Fake Timers describe (&quot;Sinon Examples&quot;,  function (){ it ('FakeTimers',  function (){ var  data =  new ...
Sinon.js/Fake Timers describe (&quot;Sinon Examples&quot;,  function (){ it ('FakeTimers',  function (){ var  clock =  sin...
Sinon.js/Fake Server describe('Sinon',function(){ var server;  beforeEach(function() { var server = sinon.useFakeServer();...
Referências <ul><li>JasmineBDD </li></ul><ul><ul><li>http://pivotal.github.com/jasmine/ </li></ul></ul><ul><li>Sinon.js </...
Obrigado [email_address] [email_address] intelie.com/trabalhe
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Jasmine - Sinon - BrazilJS
Upcoming SlideShare
Loading in …5
×

Jasmine - Sinon - BrazilJS

2,868 views

Published on

Lightning talk realizado no BrazilJS

Published in: Technology, Business
  • Be the first to comment

Jasmine - Sinon - BrazilJS

  1. 1. Jasmine / Sinon.js Jorge Falcão Sergio Azevedo [email_address] @sergioazevedo
  2. 2. Jasmine
  3. 3. Jasmine
  4. 4. Jasmine
  5. 5. Jasmine
  6. 6. Jasmine
  7. 7. Jasmine / Spec //# ContaSpec.js # describe ('Conta', function (){ it (&quot;deve realizar saques&quot;, function (){ var conta = new Conta({saldo:1000}); conta.saca(300) expect (conta.saldo()). toEqual (300); }); }); Spec Expectation Matcher
  8. 8. Jasmine / Spec describe ('Conta', function (){ it (&quot;deve realizar saques&quot;, function (){ var conta = new Conta({saldo:1000}); conta.saca(300); expect (conta.saldo). toEqual (700); }); it (&quot;deve permitir depositos&quot;, function (){ var conta = new Conta({saldo:1000}); conta.deposita(200); expect (conta.saldo). toEqual (1200); }); });
  9. 9. Jasmine / beforeEach describe('Conta', function() { it(&quot;deve realizar saques&quot;, function() { var conta = new Conta({ saldo: 1000 }); conta.saca(300); expect(conta.saldo).toEqual(700); }); it(&quot;deve permitir depositos&quot;, function() { var conta = new Conta({ saldo: 1000 }); conta.deposita(200); expect(conta.saldo).toEqual(1200); }); });
  10. 10. Jasmine / beforeEach describe('Conta', function() { var conta; beforeEach(function() { var conta = new Conta({ saldo: 1000 }); }); it(&quot;deve realizar saques&quot;, function() { conta.saca(300); expect(conta.saldo).toEqual(700); }); it(&quot;deve permitir depositos&quot;, function() { conta.deposita(200); expect(conta.saldo).toEqual(1200); }); }); afterEach() too!
  11. 11. Jasmine / Nested Spec describe('Conta', function() { var conta; describe('Conta Sem Bloqueio', function() { beforeEach(function() { conta = new Conta({ saldo: 1000 }); }); it(&quot;deve realizar saques&quot;, function() { ... }); }); describe('Conta Bloqueada', function() { beforeEach(function() { conta = new Conta({ saldo: 1000 }); conta.bloquear(); }); it(&quot;nao deve realizar saques&quot;, function() { ... }); }); });
  12. 12. Jasmine / Matchers expect (conta.saldo). toEqual (1000); expect (conta). toBe (conta); expect (conta.titular). toMatch (/ana/); expect (conta.saldo). toBeDefined() ; expect (conta.dataEncerramento). toBeNull () ; expect (conta.saca(-500). toThrow (Error) ; expect (conta.saldo). not .toEqual(40); expect (conta). not .toBe(“Mario”); ... É possível negar um Matcher. Também é possível criar seu próprio Matcher
  13. 13. Jasmine / Spies describe ('Banco', function (){ it (&quot;deve taxar suas contas&quot;, function (){ var banco = new Banco(); var conta = new Conta(); banco.addConta(conta); spyOn (conta,'descontarTarifa'); banco.taxarContas(); expect (conta.descontarTarifa). toHaveBeenCalled (); }); });
  14. 14. Jasmine / Asynchronous specs describe (&quot;Testes Assicronos&quot;, function ({ it (&quot;exemplo com waits&quot;, function (){ var a = 1; setTimeout ( function (){ a++; console.debug(&quot;somando&quot;); }, 300); expect (a). toEqual (2); }); });
  15. 15. Jasmine / Asynchronous specs
  16. 16. Jasmine / Asynchronous specs describe (&quot;Testes Assicronos&quot;, function ({ it (&quot;exemplo com waits&quot;, function (){ var a = 1; setTimeout ( function (){ a++; console.debug(&quot;somando&quot;); }, 300); expect (a). toEqual (2); }); });
  17. 17. Jasmine / Asynchronous specs describe (&quot;Testes Assicronos&quot;, function ({ it (&quot;exemplo com waits&quot;, function (){ var a = 1; setTimeout ( function (){ a++; console.debug(&quot;somando&quot;); }, 300); waits(300); runs(function() { expect(a).toEqual(2); }); expect (a). toEqual (2); }); });
  18. 18. Jasmine / Asynchronous specs
  19. 19. Jasmine / Asynchronous specs it(&quot;exemplo com waitsFor&quot;, function() { var a = 1; var somado = false; setTimeout(function() { a++; console.debug(&quot;somando&quot;); somado = true; }, 1000); waitsFor(function() { return somado; }, &quot;aguardando soma&quot;, 4000); runs(function() { expect(a).toEqual(2); }); });
  20. 20. Sinon.JS
  21. 21. Sinon.js <ul><li>Spies </li></ul><ul><li>Stubs </li></ul><ul><li>Mocks </li></ul><ul><li>Fake Timers </li></ul><ul><li>Fake XHR </li></ul><ul><li>Fake Server </li></ul>
  22. 22. Sinon.js
  23. 23. Sinon.js/Fake Timers describe (&quot;Sinon Examples&quot;, function (){ it ('FakeTimers', function (){ var data = new Date(); expect ( elapsedTime (myDate)). toEqual (2); }); }); Depende da velocidade do browser!
  24. 24. Sinon.js/Fake Timers describe (&quot;Sinon Examples&quot;, function (){ it ('FakeTimers', function (){ var clock = sinon . UseFakeTimers (); var data = new Date(); clock. tick (2000); expect ( elapsedTime (myDate)). toEqual (2); clock. restore (); }); }); beforeEach e afterEach podem ser uteis.
  25. 25. Sinon.js/Fake Server describe('Sinon',function(){ var server; beforeEach(function() { var server = sinon.useFakeServer(); }); afterEach(function() { server.restore(); }); it(&quot;FakeServer example&quot;, function(){ server.respondWith('GET', '/users.json', [200, {&quot;Content-Type&quot; : &quot;application/json&quot;}, '[{id:1, login: &quot;Jason&quot;}]']); var callback = sinon.spy(); $.ajax({ url: '/users.json', success: callback }); assert( callback.calledWith([{id: 1, login: &quot;Json&quot;}]); ); }); });
  26. 26. Referências <ul><li>JasmineBDD </li></ul><ul><ul><li>http://pivotal.github.com/jasmine/ </li></ul></ul><ul><li>Sinon.js </li></ul><ul><ul><li>http://sinonjs.org/ </li></ul></ul>
  27. 27. Obrigado [email_address] [email_address] intelie.com/trabalhe

×