Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

injected-loader

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

injected-loader

Webpack dependency injection for testing

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
24
increased by300%
Maintainers
1
Weekly downloads
 
Created
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

Package last updated on 11 Jun 2015

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc