Created
August 15, 2010 08:59
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vows = require('vows'), assert = require('assert'), path = require('path'); | |
var application = require(path.join(process.cwd(), 'public', 'javascripts', 'application')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var SomeHandler = { }; | |
$.load(function() { SomeHandler.do_stuff(); }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(window, undefined) { | |
var jQuery = {}; | |
window.jQuery = window.$ = jQuery; | |
})(window); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(window, $) { | |
var SomeHandler = {}; | |
$.load(function() { SomeHandler.do_stuff(); }); | |
window.SomeHandler = SomeHandler; | |
})(window, jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(window, $) { | |
var SomeHandler = {}; | |
$.load(function() { SomeHandler.do_stuff(); }); | |
window.SomeHandler = SomeHandler; | |
})(this.window || exports, this.jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(window, $) { | |
var SomeHandler = { | |
load: function() { | |
$.load(function() { SomeHandler.do_stuff(); }); | |
} | |
}; | |
window.SomeHandler = SomeHandler; | |
})(this.window || exports, this.jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
handler = { | |
handle: function(object) { | |
$('#element .' + object.name).text(object.content); | |
$('#controls .previous').hide(); | |
$('#controls .next').show(); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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