Socket
Socket
Sign inDemoInstall

@collectivehealth/unity

Package Overview
Dependencies
2
Maintainers
24
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @collectivehealth/unity

A library to make unit testing Angular 1 applications suck less.


Version published
Maintainers
24
Created

Readme

Source

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 @collectivehealth/unity

or

npm install --save-dev @collectivehealth/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 '@collectivehealth/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! 🎉

FAQs

Last updated on 02 Aug 2017

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