Skip to content

Instantly share code, notes, and snippets.

@roycehaynes
Created March 27, 2013 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roycehaynes/26376f8aa213e6de654a to your computer and use it in GitHub Desktop.
Save roycehaynes/26376f8aa213e6de654a to your computer and use it in GitHub Desktop.
config.js (aka main.js)
require.config({
deps: [
'main',
'util/jquery.cookie',
'util/sprintf',
'util/uri',
'util/hashids',
'util/sha1'
],
paths: {
// application javascript.
libs: '../assets/js',
// Libraries
util: '../vendor/js/utilities',
plugins: '../vendor/js/plugins',
jquery:'../vendor/js/jquery-1.9.1.min',
underscore: '../vendor/js/underscore-1.4.4.min',
//backbone: '../vendor/js/backbone-0.9.9.min',
backbone: '../vendor/js/backbone',
stackmob: '../vendor/js/stackmob-0.7.0',
stripe: '../vendor/js/stripe/v1/stripe',
qunit: 'tests/qunit/1.11.0/qunit',
//jasmine:'tests/jasmine/1.3.1/jasmine',
//'jasmine-html':'tests/jasmine/1.3.1/jasmine-html',
text: '../vendor/js/text'
},
shim: {
underscore: {
exports: '_'
},
backbone: {
deps: ['underscore'],
exports: 'Backbone'
},
stackmob: {
deps: ['backbone'],
exports: 'StackMob'
},
'util/hashids': [],
'util/uri': [],
'util/sprintf': [],
'util/sha1': [],
'util/jquery.cookie': [],
'plugins/backbone.safe' : ['backbone'],
'plugins/backbone.layoutmanager': ['backbone'],
'plugins/backbone.modal' : ['backbone'],
'plugins/backbone.validation.amd' : ['backbone'],
qunit: {
exports: 'QUnit'
}
}
});
define( ["stackmob", "stripe", "qunit"],
function(StackMob, Stripe, QUnit) {
// Initialize StackMob API
StackMob.init({
appName: "mycreate",
clientSubdomain: "",
publicKey: "",
apiVersion: 0,
userSchema: "user",
apiURL: "https://api.stackmob.com/"
});
//TODO: swap out for production key
Stripe.setPublishableKey('');
QUnit.config.autostart = false;
QUnit.start(); //Tests loaded, run tests
}
);
@spencercarnage
Copy link

Are you getting the error 'Uncaught TypeError: Cannot call method 'config' of undefined'?

If so, that's because of the QUnit argument that's being returned from the define statement, which is undefined. QUnit itself isn't an AMD module and therefore doesn't return anything to the define callback. The shim is providing QUnit as a global variable, however the define statement is returning a local scoped var, QUnit, as undefined. When you try to access QUnit.config.autostart, it's trying to access the local undefined var instead of the global var.

If you changed QUnit inside of the define callback function to window.QUnit, it should work. A proper solution would be to add QUnit into the stackmob deps array and remove QUnit from the define statement dependency list and the function arguments. That will keep the define statement from creating a local var of QUnit, allowing you to access the global QUnit without having to use window.QUnit.

I came up with this solution by doing a quick mock up of my own that mimics how you're loading QUnit in hopes to recreate the problem. If this doesn't solve it, I would need more info regarding the errors you're getting.

@spencercarnage
Copy link

Looking into it some more, loading QUnit through require seems to cause problems with the runner. I would load it as a separate script tag in the html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment