SlideShare a Scribd company logo
1 of 21
Download to read offline
Javascript is
software too!
(so where are the unit tests?)
        Kerry Buckley — @kerryb
  FESuffolk lightning talk 25 March 2013
http://www.flickr.com/photos/saparevo/4948914064
http://www.flickr.com/photos/igormazic/299854107
UT                            No         Yes                                                        ut/)
                                                            No            [107] (http://lbrtw.com/javascript-unit-
                                                                                                                   Developed as a learning project
                                                                          test-framework-part-1)
     JSUnit             Yes        No         Yes           No            [108] (http://www.jsunit.net/)
                                                                                                                   JSUnit is no longer actively maintain
     Enhance JS         Yes                                                                                                                                ed
                                   No         Yes           No            [10 6]
     QUnit                                                                                                         Port of Enhance PHP
                                              Yes         Yes         [109] (http://qunitjs.com/)
                                                                                                                   jQuery test harness
     RhUnit                                                           [110]
                                              Yes         Yes
                                                                      (http://www.iankent.co.uk/rhunit/)           QUnit compatible Rhino/JUnit framew
    Crosscheck                                                                                                                                             ork
                                              No          Yes         [10 7]
    J3Unit                                                                                                         Browserless java-based framework
                                          Yes             No          [111] (http://j3unit.sourceforge.net/)
    Mocha               No     Yes                                   [112]
                                          Yes             Yes
                                                                     (http://visionmedia.github.com/moch
    JSNUnit                                                                                              a/)
                                          Yes             No         [10 8]
   YUI Test          Yes       Yes        Yes           Yes          [10 9]
   JSSpec
                                          Yes             No         [11 0]
   UnitTesting                                                                                                    Behaviour-driven development framew
                                          Yes                                                                                                              ork
                                                        No          [11 1]
                                                                                                                 script.aculo.us javascript test harness
   JSpec                                                            [113]
                                          Yes          Yes                                                       Highly readable BDD, 50+ matchers
                                                                    (http://visionmedia.github.com/jspec)                                             , DOM / framework independent,
                                                                                                                 async, rhino, node.js support and mo
                                                                                                                                                      re (no longer maintained)
   Jasmine                                                          [114]                                        BDD, framework independent, easy
                                         Yes           Yes                                                                                            integration with Ruby projects
                                                                    (http://pivotal.github.com/jasmine)          and continuous builds. Allows for bot
                                                                                                                                                       h DOM-less testing and
  screw-unit                                                                                                     asynchronous testing.
                                         Yes           No           [11 2]
                                                                                                                 Requires jQuery
  Test.Simple     No[11 3]    Yes        Yes           No          [11 4]                                       Write TAP-emitting unit tests in JavaSc
                                                                                                                                                        ript and run them in your
                                                                                                                browser.
  Test.More       No[1]       Yes        Yes           No          [11 5]                                       Write TAP-emitting unit tests in JavaSc
                                                                                                                                                       ript and run them in your
  TestCase                                                                                                      browser.
                                         Yes           No          [11 6]
 TestIt
                                         Yes          Yes          [11 7]
 jsUnitTest                                                                                                     Light-weight, non-polluting, and eas
                                         Yes                                                                                                         y to set up and use
                                                    Yes[11 8]
 JSTest                                                                                                         Based on TestCase but without the Pro
                                        Yes                                                                                                             totype dependency
                                                      No          [11 9]
                                                                                                                Light-weight, non-polluting browser-b
 JSTest.NET                                                                                                                                            ased framework
                                         No           Yes         [115] (http://jstest.codeplex.com)            Browserless JavaScript unit test runner
                                                                                                                                                        for use with MsTest, XUnit,
 jsUnity          Yes                                                                                           NUnit, etc.
                              No        Yes          Yes          [116] (http://jsunity.com/)
RhinoUnit                                                                                                      Context-agnostic (JavaScript, JScript
                                        No           Yes         [12 0]                                                                              (ASP/WSH), Rhino, etc.)
                                                                                                               Rhino-based framework that allows test
JasUnit                                                                                                                                                 s to be run in Ant
                  Yes         No        Yes          No          [12 1]                                        Light-weight framework. Part of a pro
                                                                                                                                                      ject that provides Mocks and
                                                                                                               IoC.)
FireUnit
                                        Yes          No          [117] (http://fireunit.org/)                  Testing framework that provides loggin
                                                                                                                                                        g and viewing within a new
                                                                                                               tab of Firebug.
Js-test-
driver            Yes                   Yes          No          [12 2]                                        The goal of JsTestDriver is to build a
                                                                                                                                                      JavaSc
describe "2 + 2", ->
  it "is 4", ->
    expect(2 + 2).toEqual 4




describe("2 + 2", function() {
  it("should be 4", function() {
    expect(2 + 2).toEqual(4);
  });
});
$ jasmine-headless-webkit -c

Running Jasmine specs...
.
PASS: 1 test, 0 failures, 0.003 secs.

Test ordering seed: --seed 2026
encrypt = ->
  plainText = $("#plain-text").val()
  $.get "/encrypt", {text: plainText}, update

update = (data) ->
  $("#encrypted-text").val data.text

$ ->
  $("#plain-text").keyup encrypt
source "https://rubygems.org"

...

group :development, :test do
  ...
  gem "jasmine-headless-webkit"
  gem "jasmine-spec-extras"
end
src_files:
  - ["application.js"]
helpers:
  - helpers/**/*
spec_files:
  - "**/*[Ss]pec.*"
src_dir:
- app/assets/javascripts
- vendor/assets/javascripts
spec_dir: spec/javascripts
describe "Encryptor", ->
  beforeEach ->
    loadFixtures "encryptor.html"

  describe ".update", ->
    ...




<input id="plain-text" />
<input id="encrypted-text" />
describe "Encryptor", ->
  beforeEach ->
    loadFixtures "encryptor.html"

  describe ".update", ->
    it "sets the #encrypted-text element's value to the
        supplied data's text attribute", ->
      update {text: "foo"}
      expect($("#encrypted-text").val()).toEqual "foo"
Running Jasmine specs...
F
FAIL: 1 test, 1 failure, 0.003 secs.

Encryptor .update sets the #encrypted-text
element's value to the supplied data's text
attribute. (...spec/javascripts/
encryptor_spec.coffee:3)

  ReferenceError: Can't find variable: update
// Generated by CoffeeScript 1.6.1
(function() {
  var encrypt, update;

  encrypt = function() {
     var plainText;
     plainText = $("#plain-text").val();
     return $.get("/encrypt", {
       text: plainText
     }, update);
  };

  update = function(data) {
     return $("#encrypted-text").val(data.text);
  };

  $(function() {
    return $("#plain-text").keyup(encrypt);
  });

}).call(this);
class Encryptor
  constructor: ->
    $("#plain-text").keyup @encrypt

  encrypt: =>
    plainText = $("#plain-text").val()
    $.get "/encrypt", {text: plainText}, @update

  update: (data) =>
    $("#encrypted-text").val data.text

$ ->
  window.encryptor = new Encryptor
describe ".encrypt", ->
  it "requests encryption of the #plain-text field,
      calling .update on success", ->

    $("#plain-text").val "foo"
    spyOn $, "get"

    window.encryptor.encrypt()

    expect($.get).toHaveBeenCalledWith "/encrypt",
      {text: "foo"}, window.encryptor.update
someObject = {doSomething: ->}

describe "an easy mistake to make", ->
  it "catches me out all the time", ->
    spyOn someObject, "doSomething"

    # Should fail – I'm not calling doSomething
    expect(someObject.doSomething).toHaveBeenCalled




Running Jasmine specs...
.
PASS: 1 test, 0 failures, 0.004 secs.

Test ordering seed: --seed 7220
Tuesday 2 April, 7pm
  The Brewery Tap

More Related Content

More from Kerry Buckley

Ruby nooks & crannies
Ruby nooks & cranniesRuby nooks & crannies
Ruby nooks & cranniesKerry Buckley
 
Javasccript MV* frameworks
Javasccript MV* frameworksJavasccript MV* frameworks
Javasccript MV* frameworksKerry Buckley
 
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test communityKerry Buckley
 
What I learned from Seven Languages in Seven Weeks (IPRUG)
What I learned from Seven Languages in Seven Weeks (IPRUG)What I learned from Seven Languages in Seven Weeks (IPRUG)
What I learned from Seven Languages in Seven Weeks (IPRUG)Kerry Buckley
 
MongoMapper lightning talk
MongoMapper lightning talkMongoMapper lightning talk
MongoMapper lightning talkKerry Buckley
 
The secret life of bees
The secret life of beesThe secret life of bees
The secret life of beesKerry Buckley
 
Background processing
Background processingBackground processing
Background processingKerry Buckley
 
Katas, Contests and Coding Dojos
Katas, Contests and Coding DojosKatas, Contests and Coding Dojos
Katas, Contests and Coding DojosKerry Buckley
 
Kanban and Iterationless Working
Kanban and Iterationless WorkingKanban and Iterationless Working
Kanban and Iterationless WorkingKerry Buckley
 
Software Development Trends
Software Development TrendsSoftware Development Trends
Software Development TrendsKerry Buckley
 
Kanban and Iterationless Working
Kanban and Iterationless WorkingKanban and Iterationless Working
Kanban and Iterationless WorkingKerry Buckley
 

More from Kerry Buckley (20)

BDD with cucumber
BDD with cucumberBDD with cucumber
BDD with cucumber
 
Ruby nooks & crannies
Ruby nooks & cranniesRuby nooks & crannies
Ruby nooks & crannies
 
TDD refresher
TDD refresherTDD refresher
TDD refresher
 
Javasccript MV* frameworks
Javasccript MV* frameworksJavasccript MV* frameworks
Javasccript MV* frameworks
 
Tdd for BT E2E test community
Tdd for BT E2E test communityTdd for BT E2E test community
Tdd for BT E2E test community
 
7li7w devcon5
7li7w devcon57li7w devcon5
7li7w devcon5
 
What I learned from Seven Languages in Seven Weeks (IPRUG)
What I learned from Seven Languages in Seven Weeks (IPRUG)What I learned from Seven Languages in Seven Weeks (IPRUG)
What I learned from Seven Languages in Seven Weeks (IPRUG)
 
Functional ruby
Functional rubyFunctional ruby
Functional ruby
 
MongoMapper lightning talk
MongoMapper lightning talkMongoMapper lightning talk
MongoMapper lightning talk
 
Ruby
RubyRuby
Ruby
 
Cloud
CloudCloud
Cloud
 
The secret life of bees
The secret life of beesThe secret life of bees
The secret life of bees
 
Background processing
Background processingBackground processing
Background processing
 
Katas, Contests and Coding Dojos
Katas, Contests and Coding DojosKatas, Contests and Coding Dojos
Katas, Contests and Coding Dojos
 
Rack
RackRack
Rack
 
Doing REST Right
Doing REST RightDoing REST Right
Doing REST Right
 
Kanban and Iterationless Working
Kanban and Iterationless WorkingKanban and Iterationless Working
Kanban and Iterationless Working
 
Software Development Trends
Software Development TrendsSoftware Development Trends
Software Development Trends
 
TDD
TDDTDD
TDD
 
Kanban and Iterationless Working
Kanban and Iterationless WorkingKanban and Iterationless Working
Kanban and Iterationless Working
 

Recently uploaded

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

Jasmine

  • 1. Javascript is software too! (so where are the unit tests?) Kerry Buckley — @kerryb FESuffolk lightning talk 25 March 2013
  • 4. UT No Yes ut/) No [107] (http://lbrtw.com/javascript-unit- Developed as a learning project test-framework-part-1) JSUnit Yes No Yes No [108] (http://www.jsunit.net/) JSUnit is no longer actively maintain Enhance JS Yes ed No Yes No [10 6] QUnit Port of Enhance PHP Yes Yes [109] (http://qunitjs.com/) jQuery test harness RhUnit [110] Yes Yes (http://www.iankent.co.uk/rhunit/) QUnit compatible Rhino/JUnit framew Crosscheck ork No Yes [10 7] J3Unit Browserless java-based framework Yes No [111] (http://j3unit.sourceforge.net/) Mocha No Yes [112] Yes Yes (http://visionmedia.github.com/moch JSNUnit a/) Yes No [10 8] YUI Test Yes Yes Yes Yes [10 9] JSSpec Yes No [11 0] UnitTesting Behaviour-driven development framew Yes ork No [11 1] script.aculo.us javascript test harness JSpec [113] Yes Yes Highly readable BDD, 50+ matchers (http://visionmedia.github.com/jspec) , DOM / framework independent, async, rhino, node.js support and mo re (no longer maintained) Jasmine [114] BDD, framework independent, easy Yes Yes integration with Ruby projects (http://pivotal.github.com/jasmine) and continuous builds. Allows for bot h DOM-less testing and screw-unit asynchronous testing. Yes No [11 2] Requires jQuery Test.Simple No[11 3] Yes Yes No [11 4] Write TAP-emitting unit tests in JavaSc ript and run them in your browser. Test.More No[1] Yes Yes No [11 5] Write TAP-emitting unit tests in JavaSc ript and run them in your TestCase browser. Yes No [11 6] TestIt Yes Yes [11 7] jsUnitTest Light-weight, non-polluting, and eas Yes y to set up and use Yes[11 8] JSTest Based on TestCase but without the Pro Yes totype dependency No [11 9] Light-weight, non-polluting browser-b JSTest.NET ased framework No Yes [115] (http://jstest.codeplex.com) Browserless JavaScript unit test runner for use with MsTest, XUnit, jsUnity Yes NUnit, etc. No Yes Yes [116] (http://jsunity.com/) RhinoUnit Context-agnostic (JavaScript, JScript No Yes [12 0] (ASP/WSH), Rhino, etc.) Rhino-based framework that allows test JasUnit s to be run in Ant Yes No Yes No [12 1] Light-weight framework. Part of a pro ject that provides Mocks and IoC.) FireUnit Yes No [117] (http://fireunit.org/) Testing framework that provides loggin g and viewing within a new tab of Firebug. Js-test- driver Yes Yes No [12 2] The goal of JsTestDriver is to build a JavaSc
  • 5.
  • 6.
  • 7. describe "2 + 2", -> it "is 4", -> expect(2 + 2).toEqual 4 describe("2 + 2", function() { it("should be 4", function() { expect(2 + 2).toEqual(4); }); });
  • 8. $ jasmine-headless-webkit -c Running Jasmine specs... . PASS: 1 test, 0 failures, 0.003 secs. Test ordering seed: --seed 2026
  • 9.
  • 10. encrypt = -> plainText = $("#plain-text").val() $.get "/encrypt", {text: plainText}, update update = (data) -> $("#encrypted-text").val data.text $ -> $("#plain-text").keyup encrypt
  • 11. source "https://rubygems.org" ... group :development, :test do ... gem "jasmine-headless-webkit" gem "jasmine-spec-extras" end
  • 12. src_files: - ["application.js"] helpers: - helpers/**/* spec_files: - "**/*[Ss]pec.*" src_dir: - app/assets/javascripts - vendor/assets/javascripts spec_dir: spec/javascripts
  • 13. describe "Encryptor", -> beforeEach -> loadFixtures "encryptor.html" describe ".update", -> ... <input id="plain-text" /> <input id="encrypted-text" />
  • 14. describe "Encryptor", -> beforeEach -> loadFixtures "encryptor.html" describe ".update", -> it "sets the #encrypted-text element's value to the supplied data's text attribute", -> update {text: "foo"} expect($("#encrypted-text").val()).toEqual "foo"
  • 15. Running Jasmine specs... F FAIL: 1 test, 1 failure, 0.003 secs. Encryptor .update sets the #encrypted-text element's value to the supplied data's text attribute. (...spec/javascripts/ encryptor_spec.coffee:3) ReferenceError: Can't find variable: update
  • 16. // Generated by CoffeeScript 1.6.1 (function() { var encrypt, update; encrypt = function() { var plainText; plainText = $("#plain-text").val(); return $.get("/encrypt", { text: plainText }, update); }; update = function(data) { return $("#encrypted-text").val(data.text); }; $(function() { return $("#plain-text").keyup(encrypt); }); }).call(this);
  • 17. class Encryptor constructor: -> $("#plain-text").keyup @encrypt encrypt: => plainText = $("#plain-text").val() $.get "/encrypt", {text: plainText}, @update update: (data) => $("#encrypted-text").val data.text $ -> window.encryptor = new Encryptor
  • 18. describe ".encrypt", -> it "requests encryption of the #plain-text field, calling .update on success", -> $("#plain-text").val "foo" spyOn $, "get" window.encryptor.encrypt() expect($.get).toHaveBeenCalledWith "/encrypt", {text: "foo"}, window.encryptor.update
  • 19. someObject = {doSomething: ->} describe "an easy mistake to make", -> it "catches me out all the time", -> spyOn someObject, "doSomething" # Should fail – I'm not calling doSomething expect(someObject.doSomething).toHaveBeenCalled Running Jasmine specs... . PASS: 1 test, 0 failures, 0.004 secs. Test ordering seed: --seed 7220
  • 20.
  • 21. Tuesday 2 April, 7pm The Brewery Tap