#sjsJustin ## background * ⚡️ 20 minutes! ⚡️ * ~~purposes of each type of test~~ * ~~integration tests~~ * ~~frameworks vs. TDD~~ * a handful of situational tactics
#sjsJustin ## background * ⚡️ 20 minutes! ⚡️ * ~~purposes of each type of test~~ * ~~integration tests~~ * ~~frameworks vs. TDD~~ * a handful of situational tactics * using Jasmine
#sjsJustin ## background * ⚡️ 20 minutes! ⚡️ * ~~purposes of each type of test~~ * ~~integration tests~~ * ~~frameworks vs. TDD~~ * a handful of situational tactics * using Jasmine * generally applicable
#sjsJustin ## background * ⚡️ 20 minutes! ⚡️ * ~~purposes of each type of test~~ * ~~integration tests~~ * ~~frameworks vs. TDD~~ * a handful of situational tactics * using Jasmine * generally applicable-ish
#sjsJustin ## background * ⚡️ 20 minutes! ⚡️ * ~~purposes of each type of test~~ * ~~integration tests~~ * ~~frameworks vs. TDD~~ * a handful of situational tactics * using Jasmine * generally applicable-ish *ymmv*
#sjsJustin ## syntax ### What I do ! * write specs in CoffeeScript * use the *-given DSL * jasmine-given ported rspec-given * mocha-given ported jasmine-given
#sjsJustin ## test runner ### What I don't do ! * default plain HTML test runner * jasmine-maven-plugin * jasmine-rails * any server-side-dependent plugin
#sjsJustin ### What I don't do ! * start a fake server that can stub & verify XHRs * monkey-patch the browser's XHR facilities * invoke code by triggering UI events ## ajax & ui events
#sjsJustin ### What's the problem? ! * too integrated for unit tests * test pain isn't actionable (e.g. “only mock what you own”) * raises concerns better handled by integrated tests ## ajax & ui events
#sjsJustin ### What's the problem? ! * too integrated for unit tests * test pain isn't actionable (e.g. “only mock what you own”) * raises concerns better handled by integrated tests * no pressure to improve private APIs ## ajax & ui events
#sjsJustin ### What I do ! * wrap native/3rd party libs with objects I own * in unit tests, mock wrappers away * test pain? -> improve wrapper API ! ## ajax & ui events
#sjsJustin ### What I do ! * wrap native/3rd party libs with objects I own * in unit tests, mock wrappers away * test pain? -> improve wrapper API * wrappers specify our dependence ! ## ajax & ui events
#sjsJustin ### What I do ! * wrap native/3rd party libs with objects I own * in unit tests, mock wrappers away * test pain? -> improve wrapper API * wrappers specify our dependence * don’t (typically) test wrappers ## ajax & ui events
#sjsJustin ## asynchronous code ### What's the problem? ! * test yields execution control * lots of noise in test setup * speed/timeout concerns * hard to debug race conditions
#sjsJustin ## asynchronous code ### What's the problem? ! * test yields execution control * lots of noise in test setup * speed/timeout concerns * hard to debug race conditions * many reasons for tests to fail
#sjsJustin ## asynchronous code ### What I do ! * only write async APIs when useful * extract callbacks out of app code and into decorators and mixins * consider promises over callbacks
#sjsJustin ## asynchronous code ### What I do ! * only write async APIs when useful * extract callbacks out of app code and into decorators and mixins * consider promises over callbacks * use jasmine-stealth to capture & discretely test callback functions
#sjsJustin ## the dom ### What's the problem? #### not testing DOM interactions ! * most JavaScript _is_ DOMy UI code * low coverage limits suite's value
#sjsJustin ## the dom ### What's the problem? #### not testing DOM interactions ! * most JavaScript _is_ DOMy UI code * low coverage limits suite's value * you'll write *more* DOM-heavy code via path of least resistance
#sjsJustin ## the dom ### What's the problem? #### not testing DOM interactions ! * most JavaScript _is_ DOMy UI code * low coverage limits suite's value * you'll write *more* DOM-heavy code via path of least resistance * hampers true outside-in TDD
#sjsJustin ## the dom ### What's the problem? #### using HTML fixture files ! * large input -> larger everything * tests should push for small units * sharing fixtures leads to a "_Tragedy of the Commons_"
#sjsJustin ## the dom ### What I do ! * treat the DOM like a 3rd-party dependency, minimizing exposure * create HTML fixtures inline with jasmine-fixture !
#sjsJustin ## the dom ### What I do ! * treat the DOM like a 3rd-party dependency, minimizing exposure * create HTML fixtures inline with jasmine-fixture * arrive at single-purpose DOM-aware functions
#sjsJustin ## less tactically ! Know _why_ you’re testing. ! Push through the pain before deciding what is worth testing. ! Easy-to-test code is easy-to-use. Most JavaScript is hard-to-test. ! >
#sjsJustin ## less tactically ! Know _why_ you’re testing. ! Push through the pain before deciding what is worth testing. ! Easy-to-test code is easy-to-use. Most JavaScript is hard-to-test. ! >
#sjsJustin ## less tactically ! Know _why_ you’re testing. ! Push through the pain before deciding what is worth testing. ! Easy-to-test code is easy-to-use. Most JavaScript is hard-to-test. ! There’s no Right Way™ in software, just thoughtful and thoughtless approaches. >