Testing JS with Jasmine

1,702
-1

Published on

Jasmine itself and useful instruments

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

No Downloads
Views
Total Views
1,702
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
37
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Testing JS with Jasmine

    1. 1. Testing JS with JasmineJasmine itself and useful instruments
    2. 2. JavaScriptCoffeeScript
    3. 3. Jasmine instrumentsSuites beforeEachSpecs afterEachMatchers SpiesCustom Matchers Asynchronous specs
    4. 4. Jasmine instruments Spies spyOn(...).andCallThrough() spyOn(...).andReturn(arguments)Spying spyOn(...).andThrow(exception)Mocking spyOn(...).andCallFake(function)Faking callCount mostRecentCall.args argsForCall[i]
    5. 5. Jasmine Asynchronous specsruns(function)waits(timeout)waitsFor(function, optional message, optional timeout)
    6. 6. Jasmine minusesRuns in browser⌘+R (F5)No fixturesStatic JS vs AssetPipelineAJAX mocking isn’t friendly
    7. 7. Guard
    8. 8. GuardGuard is a command line toolto easily handle events on file modifications. gem guard-rspec gem guard-annotate gem guard-bundler gem guard-rails-assets gem guard-jasmine-headless-webkit
    9. 9. jasmine-headless-webkit
    10. 10. jasmine-headless-webkitIt integrates with Guard for a continuous testing setup.It compiles CoffeeScript, both for your tests and for your applicationlogic.It can be configured like RSpec, and its output is very similar to RSpecsoutput.It provides cleaner debugging and backtrace output than a lot of otherconsole-based test tools provide.Its fast.
    11. 11. jasmine-headless-webkitNeeds Qt (actually this is not a problem but Qt compiles a lot of time)-
    12. 12. jasmine-jquery
    13. 13. jasmine-jqueryAds JQuery specific MatchersAds FixturesAds Event Spies
    14. 14. jasmine-jquery MatcherstoBe selector toContain selectortoBeChecked toExisttoBeEmpty toHaveAttr name, valuetoBeHidden toHaveClass classNametoBeSelected toHandle eventNametoBeVisible etc...
    15. 15. jasmine-jquery Fixtures<div id="my-fixture">some complex content here</div>loadFixtures myfixture.html$(#my-fixture).myTestedPlugin()expect($(#my-fixture)).to...
    16. 16. jasmine-jquery Event SpiesspyOnEvent $(#some_element), click$(#some_element).click()expect(click).toHaveBeenTriggeredOn $#some_element
    17. 17. jasmine-ajax
    18. 18. jasmine-ajax1.Defining test responses2.Installing the mock3.Defining the response for each request4.Inspecting Ajax requests and setting expectations on them
    19. 19. Time for code
    20. 20. Linkshttps://github.com/pivotal/jasmine/wikihttp://jashkenas.github.com/coffee-script/http://johnbintz.github.com/jasmine-headless-webkit/https://github.com/velesin/jasmine-jqueryhttps://github.com/pivotal/jasmine-ajaxhttps://github.com/guard/guard/wiki/List-of-available-Guards

    ×