Your SlideShare is downloading. ×
André Faria Gomes   @andrefaria
Jasmine is a behavior-drivendevelopment framework for testing       your JavaScript code.
It does not depend on any other    JavaScript frameworks
It does not require a DOM
It has a clean, obvious syntax so that      you can easily write tests.
Specs
Expectations
Suites
Nested
Disabling      describe => xdescribe            it => xit
Matchers expect(x).toEqual(y); expect(x).toBe(y); //same expect(x).toMatch(pattern); //regex expect(x).toBeDefined(); //no...
Your Matchers
Before & After
Spies  Spies are automatically removed after each spec.  They may be set in the beforeEach function
Spying Static Methods
Spying Instance Methods
Spying CallBacks
Spying AJAX
Spying Matchersexpect(x).toHaveBeenCalled()expect(x).toHaveBeenCalledWith(arguments)expect(x).not.toHaveBeenCalled()expect...
Asynchronous Specs   runs
Asynchronous Specs   waiting
Asynchronous Specs   waiting condiction
HTML               /srcSpecRunner.html   /spec
RubyGem
NodeJSpackage     npm install jasmine-node --global     jasmine-node scripts
Javamaven
Referenceshttps://github.com/pivotal/jasmine
Testing Javascript with Jasmine
Upcoming SlideShare
Loading in...5
×

Testing Javascript with Jasmine

3,055

Published on

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

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

No Downloads
Views
Total Views
3,055
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

Transcript of "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

×