• Save
Testing Javascript with Jasmine
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Testing Javascript with Jasmine

on

  • 3,416 views

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

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

Statistics

Views

Total Views
3,416
Views on SlideShare
3,415
Embed Views
1

Actions

Likes
8
Downloads
0
Comments
0

1 Embed 1

http://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Testing Javascript with Jasmine Presentation Transcript

  • 1. André Faria Gomes @andrefaria
  • 2. Jasmine is a behavior-drivendevelopment framework for testing your JavaScript code.
  • 3. It does not depend on any other JavaScript frameworks
  • 4. It does not require a DOM
  • 5. It has a clean, obvious syntax so that you can easily write tests.
  • 6. Specs
  • 7. Expectations
  • 8. Suites
  • 9. Nested
  • 10. Disabling describe => xdescribe it => xit
  • 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. Your Matchers
  • 13. Before & After
  • 14. Spies Spies are automatically removed after each spec. They may be set in the beforeEach function
  • 15. Spying Static Methods
  • 16. Spying Instance Methods
  • 17. Spying CallBacks
  • 18. Spying AJAX
  • 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. Asynchronous Specs runs
  • 21. Asynchronous Specs waiting
  • 22. Asynchronous Specs waiting condiction
  • 23. HTML /srcSpecRunner.html /spec
  • 24. RubyGem
  • 25. NodeJSpackage npm install jasmine-node --global jasmine-node scripts
  • 26. Javamaven
  • 27. Referenceshttps://github.com/pivotal/jasmine