Repository: angular/angular.js
File: test/ng/compileSpec.js (JavaScript)

Code before:
        expect(controller2Called).toBe(true);
      });
    });


    it('should bind to multiple directives controllers via object notation (new scope)', function() {
      var controller1Called = false;
      var controller2Called = false;
      module(function($compileProvider, $controllerProvider) {
        $compileProvider.directive('foo', valueFn({
          bindToController: {
            'data': '=fooData',
            'oneway': '<fooData',
            'str': '@fooStr',
            'fn': '&fooFn'
          },
          scope: true,
          controllerAs: 'fooCtrl',
          controller: function() {
            expect(this.data).toEqualData({'foo': 'bar', 'baz': 'biz'});
            expect(this.oneway).toEqualData({'foo': 'bar', 'baz': 'biz'});
            expect(this.str).toBe('Hello, world!');
            expect(this.fn()).toBe('called!');
            controller1Called = true;
          }
        }));
        $compileProvider.directive('bar', valueFn({
          bindToController: {
            'data': '=barData',
            'oneway': '<barData',
            'str': '@barStr',
            'fn': '&barFn'
          },
          scope: true,
          controllerAs: 'barCtrl',
          controller: function() {
            expect(this.data).toEqualData({'foo2': 'bar2', 'baz2': 'biz2'});
            expect(this.oneway).toEqualData({'foo2': 'bar2', 'baz2': 'biz2'});
            expect(this.str).toBe('Hello, second world!');
            expect(this.fn()).toBe('second called!');
            controller2Called = true;
          }
        }));
      });
      inject(function($compile, $rootScope) {
        $rootScope.fn = valueFn('called!');
        $rootScope.string = 'world';
        $rootScope.data = {'foo': 'bar','baz': 'biz'};
        $rootScope.fn2 = valueFn('second called!');
        $rootScope.string2 = 'second world';
        $rootScope.data2 = {'foo2': 'bar2', 'baz2': 'biz2'};

Review comment (suggestion):
By default in tests `$exceptionHandler` seems to throw. I had to change that to only log so that we can test that it only invokes `$exceptionHandler` once (on first usage of the directive) and any further use of the directive does not re-log the same error message.


Code after:
            'oneway': '<dirData',
            'str': '@dirStr',
            'fn': '&dirFn'
          },
          controllerAs: 'test',
          bindToController: true
        }));
      });
      inject(function($compile, $rootScope) {
        expect(function() {
          $compile('<div no-ctrl>')($rootScope);
        }).toThrowMinErr('$compile', 'noctrl',
            'Cannot bind to controller without directive \'noCtrl\'s controller.');
      });
    });


    it('should throw badrestrict on first compilation when restrict is invalid', function() {
      module(function($compileProvider, $exceptionHandlerProvider) {
        $compileProvider.directive('invalidRestrictBadString', valueFn({restrict: '"'}));
        $compileProvider.directive('invalidRestrictTrue', valueFn({restrict: true}));
        $compileProvider.directive('invalidRestrictObject', valueFn({restrict: {}}));
        $compileProvider.directive('invalidRestrictNumber', valueFn({restrict: 42}));

        // We need to test with the exceptionHandler not rethrowing...
        $exceptionHandlerProvider.mode('log');
      });

      inject(function($exceptionHandler, $compile, $rootScope) {
        $compile('<div invalid-restrict-true>')($rootScope);
        expect($exceptionHandler.errors.length).toBe(1);
        expect($exceptionHandler.errors[0]).toMatch(/\$compile.*badrestrict.*'true'/);

        $compile('<div invalid-restrict-bad-string>')($rootScope);
        $compile('<div invalid-restrict-bad-string>')($rootScope);
        expect($exceptionHandler.errors.length).toBe(2);
        expect($exceptionHandler.errors[1]).toMatch(/\$compile.*badrestrict.*'"'/);

        $compile('<div invalid-restrict-bad-string invalid-restrict-object>')($rootScope);
        expect($exceptionHandler.errors.length).toBe(3);
        expect($exceptionHandler.errors[2]).toMatch(/\$compile.*badrestrict.*'{}'/);

        $compile('<div invalid-restrict-object invalid-restrict-number>')($rootScope);
        expect($exceptionHandler.errors.length).toBe(4);
        expect($exceptionHandler.errors[3]).toMatch(/\$compile.*badrestrict.*'42'/);
      });
    });


    it('should throw noident when missing controllerAs directive property', function() {
      module(function($compileProvider) {