I want an HTML5 money widget

I want a money widget that:

– has individually editable fields for each digit
– has decimal digits (default to places for cents)
– has a currency label
– tap edits digit
– double tap edits all
– tap outside digit edits all
– swipe each digit
– swipe up increments
– swipe down decremenets
– rollover (eg 10) swipe increments next digit
– faster swipe increments faster
– keyboard entry edits all
– only keyboard inputs are numbers and decimal
– has configurable max/min
– has configurable step
– has +/- buttons that can simulate swipe
– can change currency symbol (and decimal digits)

the key feature is that it can be modified as either a single value or individual digits when it makes sense

Javascript test frameworks

JS (Node) Test Frameworks


  • Built into node.js
assert.fail(actual, expected, message, operator)
assert.ok(value, [message])
assert.equal(actual, expected, [message])
assert.doesNotThrow(block, [error], [message])


  • browser support
  • test coverage reporting
  • simple async support
  • times tests & highlights slow tests
  • global variable leak reporting
  • before, after, before each, after each hooks
  • use any assertion library you want
  • run tests matching regex


describe('Array', function(){
  describe('#indexOf()', function(){
    it('should return -1 when the value is not present', function(){


describe('User', function(){
  describe('#save()', function(){
    it('should save without error', function(done){
      var user = new User('Luna');
        if (err) throw err;


  • By TJ Holowaychuk (author of Express web framework)
  • async support
  • test coverage support using node-jscoverage
assert.length('foo', 3);
assert.includes([1,2,3], 3);

Define tests by exporting a function

exports['test String#length'] = function(){
    assert.equal(6, 'foobar'.length);

For large numbers of tests you can export a “suite”

module.exports = {
    'test String#length': function(beforeExit, assert) {
      assert.equal(6, 'foobar'.length);

Async exports

setTimeout(function() {
    exports['test async exports'] = function(){
}, 100);


  • Runs in browser or node
  • async support
  • setup & teardown functions
  • flexible reporters HTML & XUnit style output
  • allows use of mocks and stubs
exports.testSomething = function(test){
    test.ok(true, "this assertion should pass");

exports.testSomethingElse = function(test){
    test.ok(false, "this assertion should fail");


  • BDD Framework
  • can be run in browser, or node
  • Ruby Gem for rails testing
  • From Pivotal Labs (makers of Pivotal Tracker)
describe("Jasmine", function() {
  it("makes testing JavaScript awesome!", function() {


  • async BDD framework for node.js
  • executes tests in parallel
  • executes tests sequentially when there are dependencies
  • emphasis on speed of execution, clarity, and user experience
var vows = require('vows'),
    assert = require('assert');

// Create a Test Suite
vows.describe('Division by Zero').addBatch({
    'when dividing a number by zero': {
        topic: function () { return 42 / 0 },

        'we get Infinity': function (topic) {
            assert.equal (topic, Infinity);
    'but when dividing zero by zero': {
        topic: function () { return 0 / 0 },

        'we get a value which': {
            'is not a number': function (topic) {
                assert.isNaN (topic);
            'is not equal to itself': function (topic) {
                assert.notEqual (topic, topic);
}).run(); // Run it


  • A node.js cucumber implementation
  • a few extra asynchronous keywords.
  • supports 160+ languages
  • exports to VowsJS stub


  • From Rackspace
  • text, html, json reporters (no xunit?)
  • support for hooking up the coverage for services started with the process runner
  • support for aggregating code coverage reports
  • code coverage
  • test isolation — each test runs in a separate process
  • needs unix sockets?
  • process runner — keeps track of integration test dependencies via json config file

Assertion framework

var user = {
    name: 'tj'
  , pets: ['tobi', 'loki', 'jane', 'bandit']

user.should.have.property('name', 'tj');

someAsyncTask(foo, function(err, result){

for mocking

See also this list:

javascript code coverage tools


shows what lines of a program have been executed
and which have been missed
this information is useful for constructing comprehensive test suites
code coverage statistics are collected while JS is executed in a browser


Find line and branch coverage
Currently integrates with jasmine
Is a Java Project
Requires you to run code with Rhino
uses Rhino debugger interface to hook into loading source files
Format can be exported to Cobertura style XML or HTML report


Chrome Extension
Line by Line JS Code Coverage statistics
Reports which statements from internal/external scripts have been executed
Counts how many times
In browser doesn’t work
It doesn’t check source, but execution


List all scripts Firefox knows about (included in HTML)
Executes in browser?


written in javascript
uses uglifyjs parser/mangler/compressor/beautifier
for js programs executed in node
proxy to execute JS in browser in the works


uses node-bunker
provides code coverage data for your unit test library (whatever that may be)

var runforcover = require('runforcover');
var coverage = runforcover.cover(/.*/g);
coverage(function(coverageData) {
    // coverageData is an object keyed by filename.
    var stats = coverageData['/full/path/to/file.js'].stats()

    // the percentage of lines run versus total lines in file

    // the number of missing lines

    // the number of lines run (seen)

    // an array of line objects representing 'missed' lines

    stats.lines.forEach(function(line) {
	// the line number of the line:

	// returns a string containing the source data for the line:

    // return control back to the original require function


fork of runforcover
uses esprima instead of bunker
If you use ‘global’ to pass state between modules (mocha does this, for example), then you might run into issues.
Cover runs modules as if they were executed with NODE_MODULE_CONTEXTS was set.
If you start new node processes, Cover won’t work with those, as it instruments by hooking into require.

See also this blog post:


Using node.js 0.4.x with npm 1.0.x via nvm

I ran across this problem and found the following question on stackoverflow:

How can I change the version of npm using nvm?

Here’s my response:

nvm doesn’t handle npm.

So if you want to install node 0.4.x (which many packages still depend on) and use NPM, you can still use npm 1.0.x.

Install node 0.6.x (which comes with npm 1.1.x) and install nvm with npm:

npm install nvm 
. ~/nvm/nvm.sh 

Install node 0.4.x with nvm:

nvm install v0.4.12 
nvm use v0.4.12 

Install npm using install.sh:

curl http://npmjs.org/install.sh | sh 

This will detect node 0.4.12 and install npm 1.0.106 in your ~/nvm/v0.4.12/lib/node_modules folder and create symlink for nvm

~/nvm/v0.4.12/bin/npm -> ../lib/node_modules/npm/bin/npm-cli.js 

If you try to run npm, it will still give an error but if you do nvm use v0.4.12 again, it should now work.