https://github.com/aackerman/injected-loader
https://github.com/aackerman/injected-loader
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/aackerman/injected-loader
- Owner: aackerman
- Created: 2015-04-06T01:29:56.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-05-30T16:31:37.000Z (about 11 years ago)
- Last Synced: 2024-08-09T16:54:55.098Z (almost 2 years ago)
- Language: JavaScript
- Size: 168 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## injected-loader [](https://travis-ci.org/aackerman/injected-loader)
Webpack dependency injection for testing
### Usage
```js
// my_great_method.js
export default function() { return false; };
```
```js
// great_method_proxy.js
import MyGreatMethod from './my_great_method.js';
export default function(input) {
return MyGreatMethod(input);
}
```
```js
// 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();
});
});
```