Test-Drive Your JavaScript

Aidan Feldman

/afeld/tdd_js

aidanfeldman

questions

  • Who has written an automated test (in any language)?
  • Who is a beginner in JS? Intermediate? Advanced?
  • Who has done JS testing?
  • Who has done browser-level integration testing?

this

  • flavors of testing
  • test frameworks
  • runners
  • best practices
  • why test
JavaSc­ript is a community of amateurs, just like PHP is. This new era of actually designing code rather than just throwing things on the floor is a different paradigm.

– AJ ONeal on JavaScript Jabber

flavors of testing

unit testing

test a piece in isolation

integration testing

test a bunch of pieces together

test frameworks

anatomy of a test

  1. Description
  2. Setup
  3. Action
  4. Assertion

it("is described", function(){
  var subject = setup();

  subject.action();

  expect(subject.property).toBe('the expected value');
});
            

tips

Keep the change, you filthy animal.

dependency injection

test runners

browser

headless browser

node.js

JSDOM

why test

insurance

...against yourself

testable code

is better code

UX design for your code

coding from the outside in