Skip to content

Instantly share code, notes, and snippets.

@sposmen
Forked from todoubled/spec_helper.coffee
Last active August 29, 2015 13:59
Show Gist options
  • Save sposmen/10729648 to your computer and use it in GitHub Desktop.
Save sposmen/10729648 to your computer and use it in GitHub Desktop.
Emulate browser inside nodejs
var window;
if (typeof window === "undefined" || window === null) {
window = {};
}
if (typeof jQuery === "undefined" || jQuery === null) {
global.$ = require('jquery');
}
if (typeof _ === "undefined" || _ === null) {
global._ = require('underscore');
}
if (typeof Backbone === "undefined" || Backbone === null) {
global.Backbone = require('backbone');
}
if (typeof Mustache === "undefined" || Mustache === null) {
global.Mustache = require('../lib/mustache');
}
if (typeof localStorage === "undefined" || localStorage === null) {
global.localStorage = require('localStorage');
}
if (typeof Store === "undefined" || Store === null) {
global.Store = require('../lib/backbone.localStorage');
}
global.jsdom = require("jsdom").jsdom;
global.document = jsdom('<html><body></body></html>');
global.window = document.createWindow();
global.navigator = {
browser: 'foo'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment