babel-plugin-transform-ng-autoinject

2.0.2 • Public • Published

FOR BABEL 7.X INSTALL V2.X - FOR OLDER V1.X

babel-plugin-transform-ng-autoinject

When writing tests for AngularJS 1.x ease the pain of writing enormous boilerplate like this:

let $rootScope, $httpBackend
beforeEach(inject((_$rootScope_, _$httpBackend_) => {
  $rootScope = _$rootScope_;
  $httpBackend = _$httpBackend_;
}));

With the following syntax:

let $rootScope, $httpBackend
beforeEach(__autoinject($rootScope, $httpBackend));

The plugin simply transforms the __autoinject expression into the former inject(...)

The exact form the plugin outputs the autoinject expression is:

let $rootScope, $httpBackend
beforeEach(inject((_$rootScope_, _$httpBackend_) => {
  ({
    $rootScope,
    $httpBackend
  } = {
    $rootScope: _$rootScope_;
    $httpBackend: _$httpBackend_;
  });
}));

Installation

npm install --save-dev babel-plugin-transform-ng-autoinject

.babelrc

{
  "presets": ["es2016"],
  "plugins": ["transform-ng-autoinject"]
}

Readme

Keywords

none

Package Sidebar

Install

npm i babel-plugin-transform-ng-autoinject

Weekly Downloads

17

Version

2.0.2

License

MIT

Unpacked Size

7.45 kB

Total Files

10

Last publish

Collaborators

  • kamilkp