Protractor: mock angularjs attribute

32 Views Asked by At

I have a common module that does contain noDoubleClick attribute, that I'm using to prevent form buttons to be clicked twice accidentally.

(function () {
  function NoDoubleClickDirective() {
    return {
      restrict: 'A',
      link(scope, elem) {
        let clicked = false;
        elem.on('click', (e) => {
          if (clicked) {
            e.preventDefault();
          } else {
            clicked = true;
            setTimeout(() => {
              clicked = false;
            }, 3000);
          }
        });
      },
    };
  }

  angular
    .module('my.common')
    .directive('noDoubleClick', NoDoubleClickDirective);
}());

But I do not want this feature while running tests with protractor. Is there anyway do disable the attribute?

I've tried like it so, but it does not work

onPrepare() {
    browser.addMockModule('my.common', function() {
      angular
        .module('my.common')
        .directive('noDoubleClick', () => {});
    });
}
1

There are 1 best solutions below

0
On BEST ANSWER

In order to make it work I had to put attribute in sub-module

browser.addMockModule('my.common.no-double-click', function() {
  angular
    .module('my.common.no-double-click', [])
    .directive('noDoubleClick', () => {});
});