npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-test-runner

v0.1.5

Published

Test Angular stuff without ngMock

Downloads

21

Readme

angular-test-runner

Join the chat at https://gitter.im/angular-test-runner/Lobby npm version

Micro testing library that allows you to practice TDD in Angular applications.

Installation

To install it, type:

$ npm install angular-test-runner --save-dev

Configuration

angular-test-runner has depedency on jasmine-jquery and karma-jasmine-jquery so it is required to add it as well.

// karma.conf.js
module.exports = function(config) {
  config.set({
    frameworks: ['jasmine-jquery', 'jasmine'],
    
    plugins: ['karma-jasmine-jquery']

    // ...
  })
}

Replacement for ngMock

angular-test-runner was created as a replacement of "official" Angular testing library: ngMock. It was designed to address following shortcommings of ngMock:

  1. different style of testing for each component type (controller, directive, service, etc.),
  2. long and boilerplate-rich setup of test,
  3. difficult testing of html templates and no support for interacting with DOM elements,
  4. focusing on testing objects in isolation instead of testing coherent set of behaviours (white-box testing)
  5. obscure tests with irrelevant informations exposing implentation details, especially in context of HTTP communication (need of $http.flush()) and DOM interaction (need of $scope.$digest())

Therefore angular-test-runner tries to address those issues by:

  1. providing uniform abstraction and consistent API for testing Angular parts, regardless of their type (contoller, directive, component, filter, etc.),
  2. providing higher confidence by excercising html templates and interacting with real DOM elements (black-box testing),
  3. promoting fine grained, self-encapsulated modules by enforcing testing at a module level instead of testing controllers, services, directives in isolation,
  4. avioding mocks in favour of fakes for HTTP communication, use synchronous HTTP stubbing by default (no need for $http.flush()) and asynchronous on demand,
  5. introducing compact, readable and declarative programming interface by introducing fluent interface.

Example

Following example presents tests for simple counter component.

var test = require('angular-test-runner');
var { click, expectElement } = test.actions;

describe('counter component', () => {

  var app, server, html;

  beforeEach(() => {
    app = test.app(['counterApp']);
    server = test.http();
  });

  beforeEach(() => {
    html = app.runHtml('<counter value="start"></counter>', {start: 0});  
  });
  
  it('should render counter value', () => {

    html.verify(
      expectElement('#counter').toHaveText('0')
    );
    
  });

  it('should increment counter value by 1', () => {

    html.perform(
      click.in('button#increment')
    );

    html.verify(
      expectElement('#counter').toHaveText('1')
    );
  });

  it('should increment counter value by 1', () => {

    var jsonSentToServer;

    server.post('/counter/increment', (req) => {
      jsonSentToServer = req.body();
      req.sendStatus(200);
    });

    html.perform(
      click.in('button#increment')
    );

    html.verify(
      () => expect(jsonSentToServer).toEqual({ counter: 1 })
    );
  });
  
});

Comparision to ngMock

Below you can compare angular-test-runner style of testing to traditional ngMock way. Following example was taken from Official Angular Developers Guide:

ngMock vs angular-test-runner

See more examples

Why not Protractor

While Protractor is focused on end-to-end testing Angular application as a whole (from a browser perspective), angular-test-runner focuses on testing coherent parts of application by excerising selected components in isolation.

Unlike Protractor in angular-test-runner you don't have to start your backend server nor host your html files on localhost so it is accessible to Selenium. Therefore test runner setup and configuration is much more simple.
Moreover you are not forced to test entire pages at once, but you can exercise only a tiny fragments of your html (e.g. single directive, component or filter a.k.a. pipe).

Features