Browse files

Merge remote-tracking branch 'linkedin/master' into issue_113

  • Loading branch information...
2 parents 10bc28c + b77b2eb commit 1475876375ead2957fb74eba634e12c3e686ed9c @Jakobo Jakobo committed May 31, 2012
Showing with 73 additions and 0 deletions.
  1. +4 −0 src/inject.coffee
  2. +64 −0 tests/amd/bugs.js
  3. +5 −0 tests/amd/includes/bugs/bug_117.js
View
4 src/inject.coffee
@@ -1229,6 +1229,10 @@ require.ensure = (moduleList, callback) ->
(function). Use this instead of require() when you need to load shallow dependencies
first.
###
+ # Assert moduleList is an Array or throw an exception.
+ if moduleList not instanceof Array
+ throw new Error("moduleList is not an Array")
+
# init the iframe if required
if userConfig.xd.xhr? and !xDomainRpc and !pauseRequired
createIframe()
View
64 tests/amd/bugs.js
@@ -63,4 +63,68 @@ asyncTest("#106 inline define() calls make module.exports available to later req
equal(mod.foo, "foo");
start();
});
+});
+
+asyncTest("#117 require.ensure() - if first argument (moduleList) is an Array, no exception should be thrown", 1, function() {
+ require.setModuleRoot('/tests/amd/includes/bugs');
+ require.ensure(['bug_117'], function(require){
+ ok(true, "require.ensure() called with moduleList as an Array didn't throw an exception");
+ });
+ start();
+});
+
+asyncTest("#117 require.ensure() - if first argument (moduleList) is an Object, an exception should be thrown", 1, function() {
+ require.setModuleRoot('/tests/amd/includes/bugs');
+ raises(
+ function() {
+ require.ensure({}, function(require){
+ ok(false, "require.ensure() called with moduleList as an Object should have thrown an exception");
+ });
+ });
+ start();
+});
+
+asyncTest("#117 require.ensure() - if first argument (moduleList) is a Number, an exception should be thrown", 1, function() {
+ require.setModuleRoot('/tests/amd/includes/bugs');
+ raises(
+ function() {
+ require.ensure(1, function(require){
+ ok(false, "require.ensure() called with moduleList as a Number should have thrown an exception");
+ });
+ });
+ start();
+});
+
+asyncTest("#117 require.ensure() - if first argument (moduleList) is a String, an exception should be thrown", 1, function() {
+ require.setModuleRoot('/tests/amd/includes/bugs');
+ raises(
+ function() {
+ require.ensure("invalid moduleList", function(require){
+ ok(false, "require.ensure() called with moduleList as a String should have thrown an exception");
+ });
+ });
+ start();
+});
+
+asyncTest("#117 require.ensure() - if first argument (moduleList) is null, an exception should be thrown", 1, function() {
+ require.setModuleRoot('/tests/amd/includes/bugs');
+ raises(
+ function() {
+ require.ensure(null, function(require){
+ ok(false, "require.ensure() called with moduleList as null should have thrown an exception");
+ });
+ });
+ start();
+});
+
+asyncTest("#117 require.ensure() - if first argument (moduleList) is undefined, an exception should be thrown", 1, function() {
+ require.setModuleRoot('/tests/amd/includes/bugs');
+ raises(
+ function() {
+ var moduleList;
+ require.ensure(moduleList, function(require){
+ ok(false, "require.ensure() called with moduleList as undefined should have thrown an exception");
+ });
+ });
+ start();
});
View
5 tests/amd/includes/bugs/bug_117.js
@@ -0,0 +1,5 @@
+define("bug_117", ["require", "exports", "module"], function(require, exports, module) {
+ module.exports = function(input) {
+ return "value: " + input;
+ };
+});

0 comments on commit 1475876

Please sign in to comment.