Socket
Socket
Sign inDemoInstall

injected-loader

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    injected-loader

Webpack dependency injection for testing


Version published
Maintainers
1
Install size
6.84 kB
Created

Readme

Source

injected-loader Build Status

Webpack dependency injection for testing

Usage

// my_great_method.js
export default function() { return false; };
// great_method_proxy.js
import MyGreatMethod from './my_great_method.js';

export default function(input) {
  return MyGreatMethod(input);
}
// import/require a dependency with the `injected` loader
// a function is returned that allows injecting dependecies to override
import GreatMethodProxyInjector from 'injected!./great_method_proxy';
var MockGreatMethod = jasmine.createSpy().and.returnValue(true);

// invoke the function with an object, keys must match
// import/require statements, the key './my_great_method.js'
// matches the import statement in great_method_proxy.js
let GreatMethodProxy = GreatMethodProxyInjector({
  './my_great_method.js': MockGreatMethod
});

describe('GreatMethodProxy', function(){
  it('calls our mocked method', function(){
    // our mocked method returns true instead of using the
    // original method and returning false
    expect(GreatMethodProxy()).toBe(true);
    expect(MockGreatMethod).toHaveBeenCalled();
  });
});

Keywords

FAQs

Last updated on 11 Jun 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc