Search code examples
javascriptjquerywebpackkarma-jasminemockjax

jquery.mockjax using with Webpack needing shim


Has anyone used mockjax for jasmine unit tests with webpack? I keep getting $.mockjax is undefined. It has something to do with

// NOTE: To use Mockjax as a Node module you MUST provide the factory with // a valid version of jQuery and a window object (the global scope): // var mockjax = require('jquery.mockjax')(jQuery, window);

but I can't use require in an AMD module. I've attempted to use a shim and the import-loader with webpack but I may have done something wrong because I don't fully understand the problem.


Solution

  • This is pretty old, but I missed it because of the lack of the mockjax tag! Anyway, this should have been resolved in PR #284. There was an issue about this with some suggestions, specifically:

    {
        test: require.resolve('jquery-mockjax/dist/jquery.mockjax.js'),
        use: ['imports-loader?this=>window,exports=>""']
    }