This package has been deprecated

Author message:

This package is no longer maintained.

@darkobits/unity

1.3.0 • Public • Published

unity

Unity is a library that helps you write shorter, cleaner unit tests for your Angular 1.x applications by eliminating much of the boilerplate requried to set up a test suite and by providing utility functions for common tasks.

Requirements

  • Angular >=1.3.0.
  • If you run your tests in a browser-like environment (ex: Karma + PhantomJS):
    • You may need an ES6 polyfill, like babel-polyfill.
    • You will need to run a module-bundler on your test files.
  • If you run your tests in Jest, Unity should Just Work!

Install

yarn add --dev @darkobits/unity

or

npm install --save-dev @darkobits/unity

Example

Before

let $controller;
let $document;
let $location;
let $q;
let $scope;

describe('MyController', () => {
  beforeEach(module('MyApp'));

  beforeEach(inject((_$controller_, _$document_, _$location_, _$q_) => {
    $controller = _$controller_;
    $document = _$document_;
    $location = _$location_;
    $q = _$q_;
    $scope = {};
  }));

  it('should work', () => {
    let myCtrl = $controller('MyCtrl', {
      $scope: $scope
    });

    // ...
  });
});
  • Multiple shared variables that are re-used across specs.
  • Syntax is verbose.
  • Three locations need to be updated to get access to an injectable. 😿

After

import {
  controller,
  get,
  module
} from '@darkobits/unity';

describe('MyCtrl', () => {
  let T;

  beforeEach(() => {
    module('MyApp');
    T = controller('MyCtrl');
  });

  it('should work', () => {
    // T.$scope is the controller's scope.
    // T.MyCtrl is the controller instance.
    // Use get('$document') and get('$location') to interact with other injectables.
  });
});
  • One shared variable across specs, regardless of how many injectables are being used.
  • Syntax is terse and readable.
  • Zero boilerplate to access an injectable, just use get() wherever you need it! 😺

For more information, check out the documentation. Happy testing! 🎉

Dependencies (0)

    Dev Dependencies (11)

    Package Sidebar

    Install

    npm i @darkobits/unity

    Weekly Downloads

    0

    Version

    1.3.0

    License

    Apache

    Last publish

    Collaborators

    • darkobits