Carlos Goce
Carlos Goce

Reputation: 1665

Mocking class with protractor

I am using angular with ngMaterial. I am using md-toast that comes with it. The problem is that the toasts are using timeout instead of interval and Protractor doesn't like them.

I just want to remove the md-toast calls from my tests. All my md-toast calls are on this class:

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

        @rootScope.appctrl.openCustomToastMessage()

It is possible to change the showToast method in Protractor tests?

Upvotes: 1

Views: 220

Answers (1)

Pieter Willaert
Pieter Willaert

Reputation: 879

You should look into Protractor's addMockModule()

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

(some more info: http://eitanp461.blogspot.be/2014/01/advanced-protractor-features.html)

Example mock:

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;

Upvotes: 1

Related Questions