Created
          January 29, 2012 08:34 
        
      - 
      
- 
        Save GraemeF/1697888 to your computer and use it in GitHub Desktop. 
    requireWithDeps
  
        
  
    
      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
    
  
  
    
  | var requireWithDeps = require('./requireWithDeps'); | |
| var sinon = require('sinon'); | |
| var fakejQuery = { | |
| doSomething: sinon.stub() | |
| }; | |
| var Foo = requireWithDeps('./Foo.js', {'jquery': fakejQuery}); | |
| var fooToTest = new Foo(); | |
| // start testing fooToTest | 
  
    
      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
    
  
  
    
  | define(['jquery'], function ($) { | |
| var Foo = function () { | |
| }; | |
| Foo.prototype.doSomethingWithjQuery = function () { | |
| return $.doSomething(); | |
| }; | |
| return Foo; | |
| }); | 
  
    
      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
    
  
  
    
  | var _ = require("underscore"); | |
| var requireWithDeps = function(moduleName, dependencies) { | |
| var originalDefine; | |
| if (typeof define !== "undefined") { | |
| originalDefine = define; | |
| } | |
| var moduleExports; | |
| define = function (deps, callback) { | |
| var requestedDeps = _(deps).map(function (depName) { | |
| return dependencies[depName]; | |
| }); | |
| moduleExports = callback.apply(this, requestedDeps); | |
| }; | |
| require(moduleName); | |
| define = originalDefine; | |
| return moduleExports; | |
| }; | |
| module.exports = requireWithDeps; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment