Skip to content

Instantly share code, notes, and snippets.

@mattdenner
Created August 15, 2010 08:59
Show Gist options
  • Save mattdenner/525274 to your computer and use it in GitHub Desktop.
Save mattdenner/525274 to your computer and use it in GitHub Desktop.
Snippets for testing Javascript with nodejs and vows (see http://mattdenner.github.com/2010/08/15/testing-javascript.html)
var vows = require('vows'), assert = require('assert'), path = require('path');
var application = require(path.join(process.cwd(), 'public', 'javascripts', 'application'));
var SomeHandler = { };
$.load(function() { SomeHandler.do_stuff(); });
(function(window, undefined) {
var jQuery = {};
window.jQuery = window.$ = jQuery;
})(window);
(function(window, $) {
var SomeHandler = {};
$.load(function() { SomeHandler.do_stuff(); });
window.SomeHandler = SomeHandler;
})(window, jQuery);
(function(window, $) {
var SomeHandler = {};
$.load(function() { SomeHandler.do_stuff(); });
window.SomeHandler = SomeHandler;
})(this.window || exports, this.jQuery);
(function(window, $) {
var SomeHandler = {
load: function() {
$.load(function() { SomeHandler.do_stuff(); });
}
};
window.SomeHandler = SomeHandler;
})(this.window || exports, this.jQuery);
handler = {
handle: function(object) {
$('#element .' + object.name).text(object.content);
$('#controls .previous').hide();
$('#controls .next').show();
}
};
handler = {
handle: function(object) {
this.updateTextFor(object);
this.previous().hide();
this.next().show();
},
updateTextFor: function(object) {
$('#element .' + object.name).text(object.content);
},
previous: function() {
return $('#controls .previous');
},
next: function() {
return $('#controls .next');
}
};
namespace :vows do
task :all do
format = ENV['VOWS_FORMAT']
params = Dir[File.join(%w{vows ** *_vows.js})]
params.unshift("--#{ format }") unless format.nil? or format.empty?
system('vows', *params)
end
end
desc 'Runs all of the Javascript vows for testing the Javascript (VOWS_FORMAT="spec" for more output)'
task :vows => 'vows:all'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment