Skip to content

Instantly share code, notes, and snippets.

@fivetanley
fivetanley / requirejs-sugar.js
Created July 25, 2012 15:46
Requirejs sugar
define( function( require ) {
var dep1 = require( './dep1' );
});
@fivetanley
fivetanley / blah.js
Created July 27, 2012 19:17
requirejs mocking
// what are you trying to mock...?
function Class1() {
this.class2var = new Class2()
}
function Class2() {
throw new Error( 'not implemented or too hard to test against' )
}
/*global requirejs:false requirejsVars: false*/
define( function() {
'use strict';
function randomContextName( contexts ) {
var randID = Math.random().toString( 36 ).substring( 9 );
if ( contexts[ randID ] ) {
return randomContextName( contexts );
}
return randID;
@fivetanley
fivetanley / error.js
Created July 28, 2012 17:41
Error Callback with try/catch
// Disclaimer: I am probably pretty wrong about this.
thing.handle( function( err, data ) {
try {
if ( err ) throw err
// js doesn't support specific errors like this, you can only catch a generic error...
} catch( NoNetworkConnection e ) {
window.alert( 'check your internet connection' )
} catch( InvalidPassword err ) {
window.alert( 'check your password' )
@fivetanley
fivetanley / es-discuss-july2012.md
Created July 28, 2012 17:52
ES-Discuss July 2012 Summary

ES-Discuss Summary July 2012

Take any dicussion to the ES-discuss mailing list!

Edit: This is a draft! If anybody's interested I'll continue working on this (Leave a +1 in the comments). Please use the comments ONLY for spelling/grammar/factual wrongness. Any discussion should go to ES-discuss.

[ES Discuss Archives][archives] | [Download July 2012 Archives][july-archive]

Table of Contents

var foo = requirejs.s.contexts._.defined.jquery
@fivetanley
fivetanley / jasmine.js
Created August 8, 2012 04:31
Jasmine simulate user input
define( [ 'views/SearchView' ], function( SearchView ){
describe('SearchView', function() {
var searchView, spy
beforeEach(function() {
setFixtures( $( "<input type='search' id='search'/>" ) )
searchView = new SearchView()
searchView.render()
spy = jasmine.createSpyObj( 'event', [ 'handler' ] )
})
@fivetanley
fivetanley / jasmine.js
Created August 8, 2012 04:34
jasmine again
define( [ 'views/SearchView' ], function( SearchView ){
describe('SearchView', function() {
var searchView, spy
beforeEach(function() {
setFixtures( $( "<input type='search' id='search'/>" ) )
searchView = new SearchView()
searchView.render()
spy = jasmine.createSpyObj( 'event', [ 'handler' ] )
})
define( function( require ) {
var EntryListingView = require( 'views/EntryListingView' )
describe('EntryListingView', function() {
var entryListingView
, id = 'entry'
, description = 'oaiweiul'
, entry
define( function( require ) {
var EntryListingView = require( 'views/EntryListingView' )
, $ = require( 'jquery' )
describe('EntryListingView', function() {
var entryListingView
, id = 'entry'
, entry