Angular $ httpBackend mock与Protractor不兼容

时间:2017-01-25 02:00:53

标签: angularjs protractor ngmocke2e

设定:

beforeEach(function () {
    const targetUrl = browser.baseUrl + '/#/Editor/AddRule';
    browser.ignoreSynchronization = true;
    browser.get(targetUrl);
    browser.wait(
        function () {
            return browser.getCurrentUrl().then(
                function (url) {
                    return targetUrl == decodeURIComponent(url);
                });
        }, 4000, 'taking too long to load');
    browser.addMockModule('httpMocker', function () {
        angular.module('httpMocker', ['ngApp', 'ngMockE2E'])
            .run(function ($httpBackend) {
                console.log("started");
                // Mock a response from server
                $httpBackend.whenPOST(browser.baseUrl + '/Editor/SaveRule')
                    .respond(500, {});
            });
    });
});

我正在尝试模拟一个具有范围变量的控制器,然后将其传递给角度服务并最终发布服务器。服务器有端点:

browser.baseUrl + '/Editor/SaveRule' and method is http post.

针对我运行的测试我想反对它:

it('Should present a success modal dialog upon successful rule save', function () {
  var name = element(by.css('[name="Name"]'));
  name.sendKeys('Rule Name 1');

  var ErrorCode = element(by.css('[name="ErrorCode"]'));
  ErrorCode.sendKeys('Error or warning Code');

  var englishLanguage = element(by.css('[name="Language0"]'));
  englishLanguage.sendKeys('English warning language');

  const ruleSetCheckbox = element(by.css('[name="RuleSet1"]'));
  ruleSetCheckbox.click();

  browser.pause();
  const button = element(by.css('[ng-click="form.$valid && save()"]'));
  button.click();
  browser.pause();
});

如果我在量角器暂停并手动点击我的UI上的“保存”按钮时控制,监控网络选项卡显示该请求实际上是发送给服务器并返回200而不是500,是我想要的。我已经检查过以确保端点是相同的。我做错了什么?

0 个答案:

没有答案