You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

angular-easy-test

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-easy-test

Framework for making Angular Unit Test's easier to write.

3.0.3
latest
Source
npm
Version published
Weekly downloads
295
23.43%
Maintainers
1
Weekly downloads
 
Created
Source

angular-easy-test

Circle CI Dependency Status devDependency Status npm version

A library that makes Angular unit tests easier to write.

install

npm install angular-easy-test

usage

CommonJS

var EasyTest = require('angular-easy-test');

AMD

define(['angular-easy-test'], function(EasyTest) {
  ...
});

Browser Global

<script src="angular.js"></script>
<script src="angular-mocks.js"></script>
<script src="angular-easy-test.js"></script>

Here are some examples of using EasyTest with Chai.


describe('MyService', function() {

  beforeEach(function() {
    EasyTest.mockModules('myModule myDependentModule');
    var services = EasyTest.injectify([ 'ServiceOne', '$q' ]);
    services.ServiceOne.functionToFake = function() {
      return services.$q.when('something');
    };
  });

  it('should look like my service', function(done) {
    var res = EasyTest.testService('MyService', {
      'function': 'one two',
      'number': 'three'
    });
    done(res);
  });

  it('some controller stuff', function() {
    var context = EasyTest.createTestContext('MyController');
    expect(context.$scope).to.have.property('something');
    context.controller.myFunction();
    expect(context.controller.state).to.equal('something');
  });

  it('some service stuff', function() {
    var service = EasyTest.getService('MyService');
    service.something();
    EasyTest.getService('$rootScope').$digest();
    expect(service.property).to.equal('something');
  });

  it('some directive stuff', function() {
    var element = EasyTest.compileDirective('<div my-directive></div>');
    expect(element.find('li')).to.have.length(10);
  });

});

comparison with ngMock

angular-easy-test is built on top of AngularJS's ngMock. Here is the same set of test cases implemented using just ngMock:

describe('MyService', function() {

  beforeEach(module('myModule', 'myDependentModule', function($provide, $q) {
    $provide.value('ServiceOne', {
      functionToFake: function() {
        return $q.when('something');
      };
    })
  }));

  it('should look like my service', inject(function(MyService) {
    expect(MyService.one).to.be.a('function');
    expect(MyService.two).to.be.a('function');
    expect(MyService.three).to.be.a('number');
  }));

  it('some controller stuff', inject(function($rootScope, $controller) {
    var scope = $rootScope.$new();
    var ctrl = $controller('MyController', {
      $scope: scope
    })
    expect(scope).to.have.property('something');
    ctrl.myFunction();
    expect(ctrl.state).to.equal('something');
  }));

  it('some service stuff', inject(function($rootScope, MyService) {
    MyService.something();
    $rootScope.$digest();
    expect(MyService.property).to.equal('something');
  }));

  it('some directive stuff', inject(function($compile, $rootScope) {
    var element = $compile('<div my-directive></div>')($rootScope.$new());
    expect(element.find('li')).to.have.length(10);
  }));

});

documentation

See the jsdocs.

Keywords

angular

FAQs

Package last updated on 08 Mar 2016

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