Your SlideShare is downloading. ×
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
BDD Javascript Testing with Jasmine
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

BDD Javascript Testing with Jasmine

3,125

Published on

Presentation at the Denver Java User's group August 10, 2011

Presentation at the Denver Java User's group August 10, 2011

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

No Downloads
Views
Total Views
3,125
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
56
Comments
0
Likes
7
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
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    • 1. BDD JavascriptTesting with Jasmine Scott Ryan August 2011
    • 2. AgendaSuites and SpecsMatchersBefore and A"erSpiesAsynchronous SpecsExecution
    • 3. Javascript Frameworksnode.js sinon.jsphantom.js backbone.jssammy.js spine.jsmustache.js coffeescriptzombie.js microjs.combatman.js yepnope.js
    • 4. PhilosophyShould not be tied to any browser, &ameworks, platform or host languageShould have idiomatic and unsurprising syntaxShould work anywhere javascript can run including browsers, servers,phones,etcShould not intrude in your applications territory like cluttering globalnamespaceShould play we( with IDE’s
    • 5. SetupCreate a Spec Use folders to keep organized Don’t bundle into buildCreate one or more html files to exercise your specsDecide on one or more run time strategies Server, Gradle, Maven, Node.js. jsTestDriver, etc.
    • 6. SpecsDefine your individual testsBegin with it.Set expectations to be satisfiedDisabled by naming xit.
    • 7. SuitesUsed to group specs togetherNamed using describeCan be nested to any depthDisabled by naming xdescribe
    • 8. Suites and Spec Example describe("External", function() { it(should default to the velocity of 3830 m/s,function () { var velocity = new Velocity("http://"); expect(velocity.defaultVelocity).toEqual(3830); });});
    • 9. MatchersMatchers set conditions to be satisfied.not wi( invert the matcherCustom matchers are supported Added to suites with this.addMatchers ca(
    • 10. Matchers Examplesexpect(x).toEqual(y);expect(x).not.toEqual(y);expect(x).toBeDefined();expect(x).toBeUndefined();expect(fn).toThrow(e);
    • 11. Before and AfterDescribe functions that run before and/or a"er theexecution of a suite.Specs can contain one or more a"er’s within the specdefinition to be run for that specRunners define before functions to run before each spec ina suite. Runners run before the suite wide before
    • 12. Before After Exampledescribe("External", function() { // This will run before each spec in this suite beforeEach(function () { console.log("Running before each spec."); alert("before each Spec"); }); // This will run after each spec in this suite. afterEach(function () { console.log("Run after each spec"); alert("after each Spec"); }); it(should default to the velocity in sandstone at 3830 m/s, function () { // This will run after this spec completes. this.after(function() { console.log("Run after spec 1 only") alert("Run after spec 1 only"); }); var velocity = new Velocity("http://"); expect(velocity.defaultVelocity).toEqual(3830); }); it(should fail if we check for the wrong velocity, function () {// This will run after this spec completes. this.after(function() { console.log("Run after spec 2 only which fails") alert("Run after spec 1 only which fails"); }); var velocity = new Velocity("http://"); expect(velocity.defaultVelocity).not.toEqual(3830); });});
    • 13. SpiesSupport spying, mocking and faking behaviorA spy replaces the function it is spying onSpies work we( for Ajax testingHave a set of special matchers and custom behaviorContain some special propertiesRemoved a"er each spec executes
    • 14. Spy matchers and responseexpect(x).toHaveBeenCa(ed()expect(x).toHaveBeenCa(edWith(arguments)spyOn(x,‘method’).andThrow(exception);spyOn(x,‘method’).andCa(Through();
    • 15. Spy propertiesca(CountmostRecentCa(.argsargsForCa([i];
    • 16. Asynchronous SpecsUsed to test ajax ca(s, ca(backs and eventsruns()waits(timeout)waitsFor(function, message, timeout)
    • 17. Asynchronous Examplesdescribe("Velocity", function() { it(should set value then wait 250 ms and set a new value, function() { runs(function () { this.velocity = new Velocity("http://"); var that = this; setTimeout(function () { that.velocity.defaultVelocity = 5000; }, 250); }); runs(function () { expect(this.velocity.defaultVelocity).toEqual(3830); }); waits(500); runs(function () { expect(this.velocity.defaultVelocity).toEqual(5000); }); });});
    • 18. Ajax Callsdescribe("Velocity", function() { it("should be able to get a list of recordings", function() { var recordings; var status = false; var theCall = External.retrieveRecordedJson(); theCall.success(function(inData) { recordings = inData.recordings; status = true; }); waitsFor(function() { return status; }, "Ajax Request never completed", 10000); runs(function () { expect(recordings.length).toBeGreaterThan(0); }); });});
    • 19. Run EnvironmentsNative BrowserPhantom.js
    • 20. Questionshttp://pivotal.github.com/jasmine/scott@theryansplace.com@scryan7371github - scryan7371https://github.com/scryan7371/Jasmine-Demo
    • 21. Photos

    ×