Created
October 14, 2011 14:05
-
-
Save felixflores/1287206 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Assuming you have underscore and jQuery as a project dependency. | |
// You can use this to include individual files on your jasmine specs. | |
// Sample Usage | |
requireJS('myJSfile', 'myOtherJsFile'); | |
describe("My stuff", function() { | |
it("rocks", function() { | |
// your spec | |
}); | |
}); | |
// Felix Flores (leaving this comment so that it does not | |
// get confused with http://requirejs.org/) | |
function requireJS() { | |
var files = _.map(Array.prototype.slice.call(arguments), function(file) { | |
return "public/javascripts/" + file + ".js"; | |
}); | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
_.each(files, function(file) { | |
script.src = file; | |
$('head').append(script); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Snap reaction
I'm struggling to understand the motivation driving this. I only have a couple guesses, but I may be wrong:
The problem I see with using this for #1 is that when the next spec gets executed, the JS upon which this first spec depended will still be on the page. So as a result, you wouldn't be achieving any more isolation (in fact, if any subsequent specs depend on the same script, that script might be loaded numerous times into the spec runner).
The problem with #2 is that most specs will be named to mirror the directory structure of their subject code, so explicitly declaring that at the top seems redundant.
What I do
Personally, I load all of my sources into my spec runner (prior to any specs loading) whenever I can, because it forces the scripts not to stomp on each other and guarantees me that I'll be able to package them up into a single minified or concatenated script. When I can't do that, I use jasmine.yml (or in Maven, my pom.xml) to explicitly state which sources I need. Are either of those not applicable or not good ideas from your perspective?