Skip to content

Instantly share code, notes, and snippets.

Avatar

Wilson Page wilsonpage

View GitHub Profile
View moduleA.test.js
define([/* dependencies */], function(){
nodeunit.run({
"test my module": function (test) {
// run test
}
});
View index.html
<!DOCTYPE html>
<html>
<head>
<title>DOM-shim unit tests</title>
<link rel="stylesheet" href="resources/nodeunit.css" type="text/css" />
<script src="resources/es5-shim.js"></script>
<script src="resources/nodeunit.js"></script>
<script src="../code/my/file"></script>
</head>
<body>
View moduleA.test.js
define(['moduleA.js'], function(ModuleA){
return {
"test1": function (test) {
// run test on ModuleA
},
"test2": function (test) {
// run test on ModuleA
},
View app-test.jade
head
meta(charset="utf-8")
meta(http-equiv="X-UA-Compatible", content="IE=edge,chrome=1")
title= title
link(rel='stylesheet', href='/public/js/libs/qunit/qunit.css')
script(src="/public/js/libs/qunit/qunit.js")
script(data-main="/public/js/app-test", src="/public/js/libs/require/require.js")
@wilsonpage
wilsonpage / reqUrl.js
Created Nov 25, 2011
A function I made that wraps the node http.request function to make it a little more friendly. In my case I am using it for API route testing.
View reqUrl.js
// module dependencies
var http = require('http'),
url = require('url');
/**
* UrlReq - Wraps the http.request function making it nice for unit testing APIs.
*
* @param {string} reqUrl The required url in any form
* @param {object} options An options object (this is optional)
View router.js
// ROUTES
var Routes = Backbone.Router.extend({
// Route Definitions
routes: {
'' : 'feed',
'feed' : 'feed',
'files' : 'files',
'members' : 'members',
':view/:itemID' : 'viewItem',
View router.js
// ROUTES
var Routes = Backbone.Router.extend({
// Route Definitions
routes: {
'' : 'feed',
'feed' : 'feed',
'files' : 'files',
'members' : 'members',
':view/:itemID' : 'viewItem',
@wilsonpage
wilsonpage / router.js
Created Nov 26, 2011
Example router module
View router.js
define([
'jQuery',
'Underscore',
'Backbone',
'modules/feed',
'modules/files',
'modules/members',
'modules/misc/GBL',
'modules/misc/lightbox'
], function($, _, Backbone, Feed, Files, Members, GBL, Lightbox){
@wilsonpage
wilsonpage / updateDuplicateData.js
Created Dec 3, 2011
This function is run when a user changes any of their core data to update duplicates across the database.
View updateDuplicateData.js
/**
* 'UpdateDuplicateData'
*
* Used to update user data on all models that it is duplicated on
*
* @param {object} User The main user model
* @param {object} changes An object containing the changed user attributes
* @param {Function} cb Callback - function(err){}
*
*/
@wilsonpage
wilsonpage / print_r.js
Created Dec 6, 2011
print_r() for javascript
View print_r.js
(function($){
$.print_r = (function(){
var depth = 0;
var render = function(o){
var str='',
indent = (function(){
var res="";
for(var i=0; i<depth*4; i++){ res+='&nbsp;' };
return res;