Skip to content

Instantly share code, notes, and snippets.

View wilsonpage's full-sized avatar

Wilson Page wilsonpage

View GitHub Profile
@wilsonpage
wilsonpage / moduleA.test.js
Created November 21, 2011 16:56 — forked from Raynos/x.js
define([/* dependencies */], function(){
nodeunit.run({
"test my module": function (test) {
// run test
}
});
<!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>
define(['moduleA.js'], function(ModuleA){
return {
"test1": function (test) {
// run test on ModuleA
},
"test2": function (test) {
// run test on ModuleA
},
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 November 25, 2011 14:38
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.
// 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)
@wilsonpage
wilsonpage / router.js
Created November 26, 2011 12:30
Example router
// ROUTES
var Routes = Backbone.Router.extend({
// Route Definitions
routes: {
'' : 'feed',
'feed' : 'feed',
'files' : 'files',
'members' : 'members',
':view/:itemID' : 'viewItem',
@wilsonpage
wilsonpage / router.js
Created November 26, 2011 12:31
Example router
// ROUTES
var Routes = Backbone.Router.extend({
// Route Definitions
routes: {
'' : 'feed',
'feed' : 'feed',
'files' : 'files',
'members' : 'members',
':view/:itemID' : 'viewItem',
@wilsonpage
wilsonpage / router.js
Created November 26, 2011 12:32
Example router module
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 December 3, 2011 14:46
This function is run when a user changes any of their core data to update duplicates across the database.
/**
* '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 December 6, 2011 16:13
print_r() for javascript
(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;