Testing Javascript with Jasmine

3,501 views
3,335 views

Published on

Presentation about testing Javascript with Jasmine. https://github.com/pivotal/jasmine

Published in: Technology
0 Comments
9 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,501
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
0
Comments
0
Likes
9
Embeds 0
No embeds

No notes for slide

Testing Javascript with Jasmine

  1. 1. André Faria Gomes @andrefaria
  2. 2. Jasmine is a behavior-drivendevelopment framework for testing your JavaScript code.
  3. 3. It does not depend on any other JavaScript frameworks
  4. 4. It does not require a DOM
  5. 5. It has a clean, obvious syntax so that you can easily write tests.
  6. 6. Specs
  7. 7. Expectations
  8. 8. Suites
  9. 9. Nested
  10. 10. Disabling describe => xdescribe it => xit
  11. 11. Matchers expect(x).toEqual(y); expect(x).toBe(y); //same expect(x).toMatch(pattern); //regex expect(x).toBeDefined(); //not undefined expect(x).toBeNull(); expect(x).toBeTruthy(); expect(x).toBeFalsy(); expect(x).toContain(y); //for arrays or strings expect(x).toBeLessThan(y); expect(x).toBeGreaterThan(y); expect(fn).toThrow(e); expect(x).not.toEqual(y);
  12. 12. Your Matchers
  13. 13. Before & After
  14. 14. Spies Spies are automatically removed after each spec. They may be set in the beforeEach function
  15. 15. Spying Static Methods
  16. 16. Spying Instance Methods
  17. 17. Spying CallBacks
  18. 18. Spying AJAX
  19. 19. Spying Matchersexpect(x).toHaveBeenCalled()expect(x).toHaveBeenCalledWith(arguments)expect(x).not.toHaveBeenCalled()expect(x).not.toHaveBeenCalledWith(arguments)spyOn(x, method).andCallThrough(): spies on AND calls the original function spied onspyOn(x, method).andReturn(arguments): returns passed arguments when spy is calledspyOn(x, method).andThrow(exception): throws passed exception when spy is calledspyOn(x, method).andCallFake(function): calls passed function when spy is calledSpy PropertiescallCount: returns number of times spy was calledmostRecentCall.args: returns argument array from last call to spy.argsForCall[i] returns arguments array for call i to spy.
  20. 20. Asynchronous Specs runs
  21. 21. Asynchronous Specs waiting
  22. 22. Asynchronous Specs waiting condiction
  23. 23. HTML /srcSpecRunner.html /spec
  24. 24. RubyGem
  25. 25. NodeJSpackage npm install jasmine-node --global jasmine-node scripts
  26. 26. Javamaven
  27. 27. Referenceshttps://github.com/pivotal/jasmine

×