5

whenGET is not a function but when I output the proxy var I cleary see that the function is there

{ when: [Function],
    whenGET: [Function],
    whenPUT: [Function],
    whenHEAD: [Function],
    whenPOST: [Function],
    whenDELETE: [Function],
    whenPATCH: [Function],
    whenJSONP: [Function],
    context: {},
  flush: [Function],
      syncContext: [Function],
    onLoad: [Getter] 
}

The spec

describe('Login', function () {

    var Injector = require('./helpers/injector');
    var loginPage = require('./pageObjects/LoginPage.js');
    var HttpBackend = require('http-backend-proxy');
    var proxy = new HttpBackend(browser);

    var loginJsonStub,
        loginPost,
        URLbase;
        //projectsJsonStub;

    beforeEach(function () {
        browser.get('http://localhost:9001/#');
        loginPost = {'Login': 'sjv', 'Password': 'password'};

        var injector = new Injector();
        injector.get('loginJson').then(function (result) {
            loginJsonStub = result;
        });

        var injector = new Injector();
        injector.get('URLbase').then(function (result) {
            URLbase = result;
        });
    });

    /*
     Login scenario
     */

    describe('should succeed with correct credentials and proceed to projects page', function () {

        it('should redirect to answerset page immediately if only 1 project', function () {

            loginJsonStub.Response.Payload.User.ProjectAmountIndication = 1;

            proxy.whenGET(URLbase + 'authentication/login', loginPost).respond(200, loginJsonStub);
            //httpBackend.whenGET(URLbase + 'project/getprojectsbyuserhierarchical').respond(200, {}); //projectsJsonStub.one

            loginPage.userName.sendKeys('xx\\svijver');
            loginPage.password.sendKeys('password');
            loginPage.nextButton.click();

            browser.getLocationAbsUrl();
            expect(browser.getCurrentUrl()).toContain('answersets/1');

            browser.sleep(2000);
        });
    });
});

Am I missing/overlooking something here?

San Jay Falcon
  • 993
  • 1
  • 9
  • 20

2 Answers2

0

In the http-backend-proxy module, you can see that it needs a ngMockE2E dependency (line 147).

For me, your ngMockE2E (angular built-in module) is not loaded via the angular-mocks.js script.

Zakaria
  • 14,892
  • 22
  • 84
  • 125
0

For this line: var HttpBackend = require('http-backend-proxy');

You are using an uppercase 'H' there, when you should be using lowercase 'httpBackend'

reutsey
  • 1,743
  • 1
  • 17
  • 36