SlideShare a Scribd company logo
Thomas Fuchs



  Adventures in
JavaScript Testing
http://script.aculo.us/thomas
traditional
javascript „testing“
Adventures In JavaScript Testing
alert(“please use me only
  where appropriate!”);
why?
"JavaScript is
this thing for
 funny mouse
trails, right?"
"BUT You
CAN't DEBUG
JavaScript!"
"WE DON'T NEED
NO STINKIN' TESTS
  FOR TEN LINES
    OF CODE!"
"ANYWAY, THERE
  IS NO WAY TO
 AUTOMATICALLY
TEST JAVASCRIPT!"
all of this is
 pure FUD
unit testing javascript
Adventures In JavaScript Testing
s from
B orrow nit
   Test::U
include unittest.js
(requires Prototype)
a DIV is required for
containing the test results
  (defaults to "testlog")
create a new instance of
  Test.Unit.Runner…
…this will excute all
methods starting with
      "test"
assert away!
(syntax strangeness
for more convenience
when calling assertions)
assert(expression)




 assert(true) => PASS
assert(false) => FAIL
assert(2*2==4) => PASS
assertEqual(expected, actual)




assertEqual(‘a’,’a’) => PASS
assertEqual(‘a’,’b’) => FAIL
  assertEqual(1,1) => PASS
 assertEqual(1,’1’) => PASS



           does not compare type
assertEnumEqual(expected, actual)




assertEnumEqual([1,2],[1,2]) => PASS


      assertEqual([1,2],[1,2]) => FAIL



                         assertEqual does not
                        compare enum contents
assertNotEqual(expected, actual)




assertNotEqual(‘a’,’a’) => FAIL
assertNotEqual(‘a’,’b’) => PASS
  assertNotEqual(1,1) => FAIL
 assertNotEqual(1,’1’) => FAIL



             does not compare type
assertMatch(expected, actual)




   assertMatch(/a/,’a’) => PASS
  assertMatch(/a/,’bab’) => PASS
   assertMatch(/a/,’b’) => FAIL
assertMatch(/^moo$/,’moo’) => PASS
assertIdentical(expected, actual)




assertIdentical(‘a’,’a’) => PASS
 assertIdentical(1,’1’) => FAIL




               compares type
assertNotIdentical(expected, actual)




assertNotIdentical(‘a’,’a’) => FAIL
 assertNotIdentical(1,’1’) => PASS




                 compares type
assertType(expected, actual)




assertType(String,’a’) => PASS
 assertType(Number,1) => PASS
assertType(Array,[1,2]) => PASS

        checks for a specific
            constructor
assertRaise(exceptionName, method)


assertRaise(‘ElementDoesNotExistError’,
   function(){
     new Effect.Opacity(‘invalid-element’)
   }
);

            related effects.js code
assertRespondsTo(method, obj)
assertVisible(element)


assertNotVisible(element)




    also checks if any parent
    elements are hidden and
       fails/passes on that
info(message)




   Displays arbitrary
messages in the "Message"
column of the test result
assertXYZ(params, message)
"WELL, WHAT ABOUT
   FUNCTIONS THAT
RUN ASYNCHRONOUSLY?"
wait(milliseconds, method)




   should be last statement in the
      test (but can be nested)
Benchmarking
"WELL, NICE. BUT IT'S
TEDIOUS TO RUN ALL THOSE
    TESTS MANUALLY!"
rake to the rescue
rake test:javascripts
Adventures In JavaScript Testing
Adventures In JavaScript Testing
javascript_test plugin
rake test:javascripts

                         1. launches
                         web server
2. controls
browsers           WEBrick
                                       lists results
                                        SUCCESS
                                         FAILURE
                                          ERROR
                    3. run tests
$ script/generate javascript_test muhaha
  exists test/javascript
  create test/javascript/muhaha_test.html
just
add your
  tests
(symlink required:
      app/test/javascript/assets to
app/vendor/plugins/javascript_test/assets)
Browser definitions
     (add more!)
$ script/plugin install http://dev.rubyonrails.org/svn/rails/plugins/javascript_test
…and if something
    breaks?
≈
Firebug       sliced bread

                    http://www.flickr.com/photos/teagrrl/78941282/
Firebug


Debugger
Firebug


know
your
Ajax
Safari Web Inspector
Safari Debugging
Microsoft Script
          Debugger for IE




http://blogs.msdn.com/ie/archive/2004/10/26/247912.aspx
Test with all
 browsers
you want to
  support
Adventures In JavaScript Testing
get a setup that
 doesn‘t suck
Source: http://www.flickr.com/photos/icathing/26603225/
+   +
        2 VMs:
         IE 6
         IE 7
+   +




one machine to rule them all
#prototype (freenode)
             and
Rails Spinoffs Google Group

More Related Content

PDF
Understanding JavaScript Testing
PDF
Testing JavaScript Applications
PPTX
Understanding JavaScript Testing
PDF
Testing javascript in the frontend
PDF
Painless JavaScript Testing with Jest
PDF
Jasmine - why JS tests don't smell fishy
PDF
Advanced Jasmine - Front-End JavaScript Unit Testing
PDF
Unit testing with mocha
Understanding JavaScript Testing
Testing JavaScript Applications
Understanding JavaScript Testing
Testing javascript in the frontend
Painless JavaScript Testing with Jest
Jasmine - why JS tests don't smell fishy
Advanced Jasmine - Front-End JavaScript Unit Testing
Unit testing with mocha

What's hot (20)

PDF
PL/SQL Unit Testing Can Be Fun!
PPTX
Javascript Testing with Jasmine 101
PDF
JavaScript TDD with Jasmine and Karma
PPTX
Qunit Java script Un
PDF
Introduction to Protractor
PDF
Stop Making Excuses and Start Testing Your JavaScript
PDF
Jasmine BDD for Javascript
PDF
AngularJS Unit Testing w/Karma and Jasmine
PDF
Test-Driven Development of AngularJS Applications
PDF
Unit testing JavaScript using Mocha and Node
PDF
Unit tests in node.js
KEY
Testing JS with Jasmine
KEY
Javascript unit testing, yes we can e big
PPTX
Good karma: UX Patterns and Unit Testing in Angular with Karma
PDF
Redux for ReactJS Programmers
PDF
Unit Testing Express Middleware
PDF
JS and patterns
PPTX
Full Stack Unit Testing
PDF
Unit Testing JavaScript Applications
PDF
Intro to testing Javascript with jasmine
PL/SQL Unit Testing Can Be Fun!
Javascript Testing with Jasmine 101
JavaScript TDD with Jasmine and Karma
Qunit Java script Un
Introduction to Protractor
Stop Making Excuses and Start Testing Your JavaScript
Jasmine BDD for Javascript
AngularJS Unit Testing w/Karma and Jasmine
Test-Driven Development of AngularJS Applications
Unit testing JavaScript using Mocha and Node
Unit tests in node.js
Testing JS with Jasmine
Javascript unit testing, yes we can e big
Good karma: UX Patterns and Unit Testing in Angular with Karma
Redux for ReactJS Programmers
Unit Testing Express Middleware
JS and patterns
Full Stack Unit Testing
Unit Testing JavaScript Applications
Intro to testing Javascript with jasmine
Ad

Viewers also liked (7)

PPT
JavaScript Testing: Mocha + Chai
PDF
Testing JavaScript
KEY
JSpec - A Javascript Unit Testing Framework
PDF
Intro To JavaScript Unit Testing - Ran Mizrahi
PPTX
Zero to Testing in JavaScript
PPTX
Testing Javascript Apps with Mocha and Chai
PPTX
Testing NodeJS with Mocha, Should, Sinon, and JSCoverage
JavaScript Testing: Mocha + Chai
Testing JavaScript
JSpec - A Javascript Unit Testing Framework
Intro To JavaScript Unit Testing - Ran Mizrahi
Zero to Testing in JavaScript
Testing Javascript Apps with Mocha and Chai
Testing NodeJS with Mocha, Should, Sinon, and JSCoverage
Ad

Similar to Adventures In JavaScript Testing (20)

PDF
Thomas Fuchs Presentation
PDF
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
PPTX
Testing Ext JS and Sencha Touch
PDF
Front-End Testing: Demystified
PDF
How do I write Testable Javascript?
PDF
How do I write Testable Javascript
PDF
How do I write testable javascript?
PDF
3 WAYS TO TEST YOUR COLDFUSION API
PDF
3 WAYS TO TEST YOUR COLDFUSION API -
PPTX
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
PDF
Testing, Performance Analysis, and jQuery 1.4
PDF
Rethinking Testing
PDF
Intro to JavaScript Testing
PPTX
How do I write Testable Javascript so I can Test my CF API on Server and Client
PDF
Reliable Javascript
PDF
BDD Testing and Automating from the trenches - Presented at Into The Box June...
PDF
ITB2016 -BDD testing and automation from the trenches
PDF
How to write Testable Javascript
PDF
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
KEY
Enterprise Strength Mobile JavaScript
Thomas Fuchs Presentation
JAVASCRIPT TDD(Test driven Development) & Qunit Tutorial
Testing Ext JS and Sencha Touch
Front-End Testing: Demystified
How do I write Testable Javascript?
How do I write Testable Javascript
How do I write testable javascript?
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API -
3 Ways to test your ColdFusion API - 2017 Adobe CF Summit
Testing, Performance Analysis, and jQuery 1.4
Rethinking Testing
Intro to JavaScript Testing
How do I write Testable Javascript so I can Test my CF API on Server and Client
Reliable Javascript
BDD Testing and Automating from the trenches - Presented at Into The Box June...
ITB2016 -BDD testing and automation from the trenches
How to write Testable Javascript
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
Enterprise Strength Mobile JavaScript

More from Thomas Fuchs (9)

PDF
Zepto and the rise of the JavaScript Micro-Frameworks
PDF
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
PDF
I Can't Believe It's Not Flash
PDF
Prototype & Scriptaculous
PDF
Extreme JavaScript Performance
PDF
Textorize
PDF
Ruby On Rails Introduction
KEY
Twistori Tech
PDF
Rich and Snappy Apps (No Scaling Required)
Zepto and the rise of the JavaScript Micro-Frameworks
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
I Can't Believe It's Not Flash
Prototype & Scriptaculous
Extreme JavaScript Performance
Textorize
Ruby On Rails Introduction
Twistori Tech
Rich and Snappy Apps (No Scaling Required)

Recently uploaded (20)

PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Approach and Philosophy of On baking technology
PDF
cuic standard and advanced reporting.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Review of recent advances in non-invasive hemoglobin estimation
Per capita expenditure prediction using model stacking based on satellite ima...
Building Integrated photovoltaic BIPV_UPV.pdf
MYSQL Presentation for SQL database connectivity
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Spectroscopy.pptx food analysis technology
Programs and apps: productivity, graphics, security and other tools
“AI and Expert System Decision Support & Business Intelligence Systems”
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Approach and Philosophy of On baking technology
cuic standard and advanced reporting.pdf

Adventures In JavaScript Testing