SlideShare a Scribd company logo
Zero to Testing in
JavaScript
Basics of testing in JS
About me
• Software developer for Xfinity.com
• Online: thewebivore.com, @pamasaur
• Co-organizer of Philadelphia JavaScript Developers
• Testing fanatic
Agenda
• My testing story
• Writing your first JavaScript test
• Testing frameworks
• Working testing into your workflow
My testing story
My Testing Story
• Code Retreat
• TDD
• Pairing
• Throw-away code
• Testing at work
• Now: test coverage drops
break the build
What’s the deal with testing?
• When you break it, it breaks!
• Secondary line of documentation defense
• Design tool
What do you call code without tests?
Legacy code.
Testing front-end code
• The debt in your /js folder
• Front-end code has logic too!
If you have logic, you need tests
BDD/TDD
• Behavior Driven Development
• Test-Driven Development
“Write tests to inform how you write your code”
• BDD: Describe, it, before, after, beforeEach, afterEach
• TDD: Suite, test, setup, teardown
Test Ever vs. Test Never
Writing your first JavaScript test
Writing your first JavaScript test
• Setting up your base
• Writing the test*
• Making it pass*
* The order of these is debatable
Jasmine
• jasmine.github.io
• Download a standalone version on GitHub from pivotal/jasmine
• Or use RubyGems for a Ruby environment
Mocha
• visionmedia.github.io/mocha
• Node!
• npm install –g mocha
Anatomy of a test
Describe [thing you’re testing]
It [does something you expect it to do]
Rinse and repeat.
Example test walk-through
with Mocha
var assert = require('assert');
describe("An area of my application", function() {
it("should know that 2 and 2 is 4", function(){
assert.equal(4, 2+2);
});
});
describe("An area of my application", function() {
it("should know that 2 and 2 is 4", function(){
assert.equal(4, 2+2);
});
});
var assert = require('assert');
describe( , function() {
it("should know that 2 and 2 is 4", function(){
assert.equal(4, 2+2);
});
});
var assert = require('assert');
describe("An area of my application", {
it("should know that 2 and 2 is 4", {
assert.equal(4, 2+2);
});
});
var assert = require('assert');
describe("An area of my application", function() {
it( , function(){
});
});
Zero to Testing in JavaScript
Testing concepts: Unit testing
Test your code
Spies, stubs, and mocks
• Spy: an object that records its interactions
• Stubs: fake objects
• Mocks: fake objects with expected behavior
Generally, you can SPY on a function, STUB an
object, and MOCK a service.
Live coding?
Write a test with me!
Testing Tools
Test describers
• Jasmine
• Mocha
• QUnit
• node-tap
• YUI Test
Assertions
• Chai
• should.js
• Expect.js
• better-assert
Spies, stubs, and mocks
• Sinon.js
• Jest from Facebook
Test runners
• Karma
• Teaspoon
• YUI Yeti
Bringing testing into the fold
3 tips for making testing a regular part of your world
#1: Teach testing
• Attend talks like this!
• Practice (ex. Code Retreat)
• Pair programming
#2: Code coverage
• Istanbul
• Blanket.js
• hrcov (Mozilla)
• JSCover
#3: Code review
• Quality assurance
• Mentoring
• Don’t accept without tests!
What’d we learn?
• Writing a JavaScript test
• Tools in JavaScript for testing
• Ways to create a testing culture
Thank you!
• Find me online at
• @pamasaur
• thewebivore.com (blog)
• turing.cool (podcast)
• bleedingedgepress.com (upcoming book on JS frameworks)

More Related Content

PPTX
MidwestJS Zero to Testing
PDF
Unit Testing JavaScript Applications
PDF
RSpec 2 Best practices
PDF
TDD with phpspec2
PPTX
Rspec presentation
PDF
Automated testing with RSpec
PPTX
RSpec and Rails
PDF
CBDW2014 - MockBox, get ready to mock your socks off!
MidwestJS Zero to Testing
Unit Testing JavaScript Applications
RSpec 2 Best practices
TDD with phpspec2
Rspec presentation
Automated testing with RSpec
RSpec and Rails
CBDW2014 - MockBox, get ready to mock your socks off!

What's hot (20)

PPTX
Introduction to testing in Rails
PDF
RSpec 3: The new, the old, the good
PPTX
RSpec: What, How and Why
PDF
Testing Ruby with Rspec (a beginner's guide)
PPTX
Javascript Testing with Jasmine 101
PDF
Intro to testing Javascript with jasmine
PDF
Introduction To Web Application Testing
PDF
Angularjs - Unit testing introduction
PDF
Djangocon 2014 angular + django
PDF
2011-02-03 LA RubyConf Rails3 TDD Workshop
PPTX
Random Ruby Tips - Ruby Meetup 27 Jun 2018
PDF
Javascript Test Automation Workshop (21.08.2014)
PDF
RSpec on Rails Tutorial
PDF
Writing Software not Code with Cucumber
PDF
Lunch and learn: Cucumber and Capybara
PDF
Django REST Framework
PPTX
Refactoring Away from Test Hell
PDF
Selenium bootcamp slides
PPTX
Unit testing JavaScript: Jasmine & karma intro
PDF
How to write easy-to-test JavaScript
Introduction to testing in Rails
RSpec 3: The new, the old, the good
RSpec: What, How and Why
Testing Ruby with Rspec (a beginner's guide)
Javascript Testing with Jasmine 101
Intro to testing Javascript with jasmine
Introduction To Web Application Testing
Angularjs - Unit testing introduction
Djangocon 2014 angular + django
2011-02-03 LA RubyConf Rails3 TDD Workshop
Random Ruby Tips - Ruby Meetup 27 Jun 2018
Javascript Test Automation Workshop (21.08.2014)
RSpec on Rails Tutorial
Writing Software not Code with Cucumber
Lunch and learn: Cucumber and Capybara
Django REST Framework
Refactoring Away from Test Hell
Selenium bootcamp slides
Unit testing JavaScript: Jasmine & karma intro
How to write easy-to-test JavaScript
Ad

Viewers also liked (12)

PDF
Displacing Worst Practices in CSS
PPTX
Simple Proxying in Rails
PDF
Selecting a Web Framework
PDF
WordPress 101 Sunday Session
PDF
Sadia Afroz: Detecting Hoaxes, Frauds, and Deception in Writing Style Online
PDF
Feminism & Open Source Contribution
PDF
Testing JavaScript with Jasmine
PPT
Testing Javascript with Jasmine
KEY
Jasmine
PDF
Advanced Jasmine - Front-End JavaScript Unit Testing
PDF
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
PPT
Automated Testing With Jasmine, PhantomJS and Jenkins
Displacing Worst Practices in CSS
Simple Proxying in Rails
Selecting a Web Framework
WordPress 101 Sunday Session
Sadia Afroz: Detecting Hoaxes, Frauds, and Deception in Writing Style Online
Feminism & Open Source Contribution
Testing JavaScript with Jasmine
Testing Javascript with Jasmine
Jasmine
Advanced Jasmine - Front-End JavaScript Unit Testing
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Automated Testing With Jasmine, PhantomJS and Jenkins
Ad

Similar to Zero to Testing in JavaScript (20)

PDF
Quick tour to front end unit testing using jasmine
PDF
Intro To JavaScript Unit Testing - Ran Mizrahi
ZIP
Continuous Integration For Rails Project
PDF
JSLT: JSON querying and transformation
PDF
Sleipnir presentation
PDF
20140406 loa days-tdd-with_puppet_tutorial
PPTX
JS Frameworks Day April,26 of 2014
PDF
Js fwdays unit tesing javascript(by Anna Khabibullina)
PDF
Lecture 03 - JQuery.pdf
PPTX
¡El mejor lenguaje para automatizar pruebas!
KEY
Developer testing 201: When to Mock and When to Integrate
PDF
Building XWiki
KEY
Testing Zen
 
PPTX
Building unit tests correctly
PPTX
Java script unit testing
PPTX
Js tacktalk team dev js testing performance
PDF
Behat bdd training (php) course slides pdf
PDF
Swift Micro-services and AWS Technologies
PDF
Selenium Tips & Tricks - StarWest 2015
PDF
Intro to JavaScript Testing
Quick tour to front end unit testing using jasmine
Intro To JavaScript Unit Testing - Ran Mizrahi
Continuous Integration For Rails Project
JSLT: JSON querying and transformation
Sleipnir presentation
20140406 loa days-tdd-with_puppet_tutorial
JS Frameworks Day April,26 of 2014
Js fwdays unit tesing javascript(by Anna Khabibullina)
Lecture 03 - JQuery.pdf
¡El mejor lenguaje para automatizar pruebas!
Developer testing 201: When to Mock and When to Integrate
Building XWiki
Testing Zen
 
Building unit tests correctly
Java script unit testing
Js tacktalk team dev js testing performance
Behat bdd training (php) course slides pdf
Swift Micro-services and AWS Technologies
Selenium Tips & Tricks - StarWest 2015
Intro to JavaScript Testing

More from pamselle (11)

PDF
WordPress 101 Saturday Session
PDF
Power Spriting With Compass
PPT
Aylin Caliskan: Quantifying the Translator Effect: Identifying authors and ma...
PDF
Kamelia Aryafar: Musical Genre Classification Using Sparsity-Eager Support Ve...
PDF
GDI WordPress 4 January 2012 (white)
PDF
GDI WordPress 4 January 2012
PDF
GDI WordPress 3 January 2012 (white background)
PDF
GDI WordPress 3 January 2012
PDF
GDI WordPress 2 January 2012
PDF
Gdi word press_2
PDF
GDI WordPress 1 January 2012
WordPress 101 Saturday Session
Power Spriting With Compass
Aylin Caliskan: Quantifying the Translator Effect: Identifying authors and ma...
Kamelia Aryafar: Musical Genre Classification Using Sparsity-Eager Support Ve...
GDI WordPress 4 January 2012 (white)
GDI WordPress 4 January 2012
GDI WordPress 3 January 2012 (white background)
GDI WordPress 3 January 2012
GDI WordPress 2 January 2012
Gdi word press_2
GDI WordPress 1 January 2012

Recently uploaded (20)

PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
medical staffing services at VALiNTRY
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Online Work Permit System for Fast Permit Processing
PDF
System and Network Administration Chapter 2
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
history of c programming in notes for students .pptx
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Digital Strategies for Manufacturing Companies
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPT
Introduction Database Management System for Course Database
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Which alternative to Crystal Reports is best for small or large businesses.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
medical staffing services at VALiNTRY
How to Migrate SBCGlobal Email to Yahoo Easily
Online Work Permit System for Fast Permit Processing
System and Network Administration Chapter 2
How Creative Agencies Leverage Project Management Software.pdf
history of c programming in notes for students .pptx
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Digital Strategies for Manufacturing Companies
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PTS Company Brochure 2025 (1).pdf.......
Softaken Excel to vCard Converter Software.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
ManageIQ - Sprint 268 Review - Slide Deck
Upgrade and Innovation Strategies for SAP ERP Customers
Introduction Database Management System for Course Database
Design an Analysis of Algorithms II-SECS-1021-03
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx

Zero to Testing in JavaScript

Editor's Notes

  • #30: Jasmine has its own spies, as do other test frameworks; Sinon is nice if you run into the limitations of those frameworks.
  • #34: Fascinating data, and can help you monitor code quality over time
  • #35: Code review is great for 1m reasons, and enforcing testing is just one of them