Testing Javascript with Jasmine

  • 2,829 views
Uploaded on

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

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

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,829
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
0
Comments
0
Likes
8

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

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