Using proxyquire in a browserify factor bundle
<p>Stuck with this one.</p>

<p>I am using <a href="https://laravel.com/docs/5.3/elixir" rel="nofollow noreferrer">laravel elxir</a> with <a href="https://www.npmjs.com/package/tsify" rel="nofollow noreferrer">tsify</a> to generate my js. I run the typescript through factor-bundle to split common js modules into a seperate files. I don't think though that will be a problem in this case because everything is in a spec.js</p>

<p>spec.ts</p>

<pre><code>/// &lt;reference path="../../../typings/index.d.ts" /&gt;
import "jasmine-jquery";
// @start widgets
import "./widgets/common/widget-factory/test";
</code></pre>

<p>factory-widget/index.ts </p>

<pre><code>export class WidgetFactory {
 .... this contains a require call to browser.service which i need to mock
}
</code></pre>

<p>factory-widget/test.ts</p>

<pre><code>...
import {WidgetFactory} from "./index";
const proxyRequire =  require("proxyquire");

  it("should output the factory items", ()=&gt; {

        proxyRequire('./widgets/browser.service/index',{
            "@global": true,
   });
}
</code></pre>

<p>browser-service.ts</p>

<pre><code>...
export class BrowserService implements IBrowserService{
 //details
}
</code></pre>

<p>Getting an error <code>Uncaught TypeError: require.resolve is not a function</code> on line 262. </p>

<p><a href="https://jsfiddle.net/sidouglas/5s03g4je/" rel="nofollow noreferrer">Here is the code ( yeah it's over 20,000 lines )</a> how else are you supposed to debug this stuff . ¯_(ツ)_/¯</p>

<p>I've looked at <a href="https://stackoverflow.com/questions/29939643/stubbing-with-proxyquire">Stubbing with proxyquire</a>. I am not holding my breath getting an answer on this one. </p>

<p>Edit: 06-09-2016
Proxquire is needed to overide the require call in the boot method of the WidgetFactory class</p>

<p>In factory-widget/index.ts:</p>

<pre><code>boot(output = true):any {
        let required = {};

        if (this._sorted.length) {
            this._sorted.forEach((key)=&gt; {
                if (output) {
                    console.log(`${this._path}${key}/index`);
                    // this is where is need to overide the call to require. 
                    required[key] = require(`${this._path}${key}/index`);
                }
            });

            this._sorted.forEach((key)=&gt; {

                let dependencies = {},
                    module = this._factory[key];

                if (module.hasOwnProperty(this.dependencyKey)) {
                    module[this.dependencyKey].map((key)=&gt; {
                        dependencies[_.camelCase(key)] = this.isService(module) ? new required[key] : key;
                    });
                }

                if (this.isTag(module)) {
                    if (output) {
                        document.addEventListener("DOMContentLoaded", ()=&gt; {
                            riot.mount(key, dependencies);
                        });
                    }
                    //console.log(key,dependencies);
                }
                else {

                }
            })
        }
    }
</code></pre>