node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »


Http Backend

Build Status

Http backend mock module for protractor


npm install httpbackend

include angular mock script

Simple Usage

var HttpBackend = require('httpbackend');
var backend = null;
describe('Test Http backend methods', function() {
    beforeEach(function() {
        backend = new HttpBackend(browser);
    afterEach(function() {
    it('Test whenGET with string response', function() {
        var result = element(by.binding('result'));
   it('Test whenPOST with function as response', function() {
        backend.whenPOST(/result/).respond(function(method, url, data) {
            return [200, data];
        var result = element(by.binding('result'));

Advanced Usage


HttpBackend workflow is quite simple:

  • On browser.get()` a mock module is injected to your angularjs application
  • On when*or when you call manually backend.sync(), fixtures is synchronised with your angularjs app.

Increase perfomance

For perfomance issue you can disable auto sync:

    var backend = new HttpBackend(brower, {autoSync: false});
    //Then you should manually call sync function 

Httpbackend Methods

  • when GET, POST, HEAD, PUT, JSONP add a fixtures, accept literal object, or a callback
  • sync, manualy sync fixtures
  • clear, clear http backend module
  • reset, reset all fixture

Development and test

Init project

bower install
npm install

Update Webdriver (used by Grunt)

./node_modules/.bin/webdriver-manager update

Launch test

npm test