The Situation:
http://theshorereporter.blogspot.com/p/cast.html
You have a data-driven application...
...and a JavaScript app using these data services.
http://www.compositesw.com/data-virtualization/data-services/
And you have JavaScript tests...
// /test/front-end.js
// Note to future self: write tests.
// Note from future self: thanks, jerk.
Well, you want to have JavaScript Tests...
Web Application Testing
http://www.aventure.ac.in/the-russian-riddle/
- Test our client application code
- No changes to our application source code
- Handle successes and errors
- Test both expected and unexpected data
Ajax
The Hunger Tests: Mockingjax
- Intercept the XMLHttpRequest
- Inspect the URL, headers, and data
- Execute callbacks with mock data
http://www.imdb.com/media/rm550033152/tt1951265?ref_=ttmd_md_pv
What should I use?
Whatever makes your workflow easier.
Not Helpful.
Yes, it is.
Let's look at some sample code...
Beer
Search for a beer
Mark a beer as a "favorite"
Rate a beer
http://pngimg.com/download/2330
Pseudo Test-code
Just like real tests, except they actually pass.
http://blakehall.github.io/tugboat-session-slides
But what happens when the server goes down?
Idempotency
Just like real potency, only more idem.
This is great, but I don't
live in the pseudo world...
... or do you?
jQuery Mockjax
Note: I maintain this one. ;)
Angular
(ng-mocks and $httpBackend)
Angular Setup
<html ng-app='testApp'>
<head>
...
<script src="angular.js">
<script src="angular-mocks.js">
...
</head>
Installing the Ajax Server
Dynamically Composing Responses
jQuery Mockjax
asynchronous mock response
jQuery Mockjax
forced lag; response headers
jQuery Mockjax
forced timeout
jQuery Mockjax
external data (proxy)
jQuery Mockjax
custom matching; external data (proxy)
Wrapping Things Up
Test your JavaScript code. ಠ_ಠ
Don't rely on external services (even your own).
Find a library that works for you!
http://chainchomp2.deviantart.com/art/Rapper-Ponies-450348867