Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Simple drop-in syntax sugar for Jasmine 2.X test framework to enhance testing of async (promise) functionality in Angular 1.X applications.

Library adds extra global methods which handle async tests implicitly without need to call $rootScope.$digest();, $timeout.flush();,$httpBackend.flush();, or done(); manually. Only thing you need to do is to return the promise in your test function. This approach was inspired by Mocha test framework which waits for resolution of returned promises by default before progressing to next test block.

Standard Jasmine 2.X test vs jasmine-async-sugar

// standard test
// ... initialize angular module, inject $rootScope, $timeout, $httpBackend and service

it('tests async functionality in standard way', function(done) {

        .then(function(response) {
            // call done() explicitly

    // we use $timeout in service, which is mocked because we included angular-mocks so we have to trigger manually
    // we have to call $rootScope.$digest() to process pending promises in angular context
    // we have to call $httpBackend.flush to process pending requests
    //Be aware, that the upper three functions must be callen in the correct order, 
    //depending on the implementation of the code under test

    // vs
// jasmine-async-sugar

itAsync('tests async functionality without "done", manual "$rootScope.$digest" and "$timeout.flush" triggering', function() {

    // only thing we need to do is return promise 
    // $rootScope.$digest(), $timeout.flush() and done() are handled automatically by library
    return AsyncService.resolveAsync()
        .then(function(response) {


Supported methods

  • itAsync
  • fitAsync
  • xitAsync
  • beforeEachAsync
  • beforeAllAsync
  • afterEachAsync
  • afterAllAsync

How to use it?

  1. bower install jasmine-async-sugar --save-dev or bower i jasmine-async-sugar -D
  2. add jasmine-async-sugar.js reference to files array in karma.conf.js or in karma task of grunt (gulp or other build system...)
  3. adjust your tests to use async methods

Example karma.conf.js

module.exports = function(config) {

        // ...
        files: [
          // standard angular testing setup
          // our drop in library file
          // test app and spec files
        // ...

Example of tests using async methods

Check example application and corresponding tests.


Library was created because we encountered problem using standard $rootScope.$digest(); at the end of the test in one particular situation where we were chaining Angular's $q and Node's q promises together. In that case one call to $rootScope.$digest(); isn't enough even if all q promises are properly wrapped with $q.when(qPromise);. Library internaly uses setInterval, which will call $rootScope.$digest(); until all chained promises are resolved and done(); called. At the end the inteval is cleared.


Please, feel free to submit bugs (prefferably with pull requests) or new features.

How to run tests?

  1. clone repository git clone
  2. install dependencies by running npm install and bower install
  3. run tests by running npm test


Simple drop-in syntax sugar for Jasmine 2.X test framework to enhance testing of async (promise) functionality to be used with Angular 1.X







No packages published

Contributors 4