samedi 28 janvier 2017

$compile: ctreq error not been thrown after upgrade to angular 1.61

I had just started the migration from angular 1.48 -> 1.61 I had left with a unit test which refuses to pass. We want to verify that the directive we wrote, will not change in the future such that it will always remain with the require attribute.

Here is the directive definition:

angular.module('ourApp')
    .directive('ourdirective', ['$timeout', function($timeout) {
    return {
      restrict: 'AE',
       require: 'ngModel',
       scope: {
         options:'=?',
         max:'=',
         ngModel : "="
    },
    templateUrl: 'ourhtmltemplate.html'
    link: function(scope, elt, attrs, ctrl) { // some code here }

And here is the unit test which we wrote for that one. You can assume that there are no compilation error of any kind, and that other tests are flying high.

it('should throw if no ng model present', function() {
  expect(function() {
    buildElement("<ourdirective ></ourdirective>");
  }).toThrowError();
};

function buildElement(html) {
  element = angular.element(html);
  $compile(element)($rootScope);
  $rootScope.$digest();
  $rootScope.select = {}
  isolatedScope = element.isolateScope();
  $rootScope.$apply(function() {});
}

We are using the following packages:

"angular": "1.6.1", "angular-mocks": "1.6.1", "jasmine-expect": "1.22", "karma": "^0.12.31", "karma-jasmine": "^0.3.5", "karma-jasmine-matchers": "^0.1.3", "karma-phantomjs-launcher": "^0.1.4",

any help would be most apritiated.

Aucun commentaire:

Enregistrer un commentaire