用量角器嘲弄课

时间:2015-10-20 08:14:52

标签: angularjs protractor

我正在使用ngMaterial的角度。我正在使用随附的md-toast。问题是吐司使用的是超时而不是间隔,而量角器并不喜欢它们。

我只是想从我的测试中删除md-toast调用。我所有的md-toast调用都在这个类上:

# Coffeescript
class MyAppController extends MyAppBase
    showToast: (msg, type) ->
        @rootScope.customToastMessage =
            toast_type: type
            messageString: msg

        @rootScope.appctrl.openCustomToastMessage()

可以在Protractor测试中更改showToast方法吗?

1 个答案:

答案 0 :(得分:1)

你应该研究一下Protractor的addMockModule()

  

http://angular.github.io/protractor/#/api?view=Protractor.prototype.addMockModule

(更多信息:http://eitanp461.blogspot.be/2014/01/advanced-protractor-features.html

示例模拟:

var MdToastMock = function () {

  this.show = function (toast) {
    this.position = toast._position;
    this.content = toast._content;
  };

  this.simple = function () {
    var self = this;
    self.content = function (content) {
      self._content = content;
      return self;
    };
    self._position = '';
    self.position = function (position) {
      self._position = position;
      return self;
    };
    return this;
  };

  spyOn(this, 'show').and.callThrough();
};

return MdToastMock;