AngularJS – Unit Testing Directive Scope Binding

app.js

var app = angular.module("app", []);

app.directive("ehSimple", function() {
    return {
        scope: {
            ehSimple: "="
      },
        link: linkFn
    }

    function linkFn(scope, element) {
        element.addClass("plain");

        element.bind("click", function() {
            scope.clicked = true;

            scope.ehSimple.message += " world";
        })
    }
})

directive.spec.js

describe("Hello world", function() {
    var element;
    var $scope;
    beforeEach(module("app"));
    beforeEach(inject(function($compile, $rootScope) {
        $scope = $rootScope;
        $scope.data = {message: "Hello"};
        element = angular.element("<div eh-simple='data'>{{2 + 2}}</div>");
        $compile(element)($rootScope);
    }))

    it('should equal 4', function() {
    $scope.$digest();
    expect(element.html()).toBe("4");
  })

  describe("ehSimple", function() {
    it("should add a class of plain", function() {
        expect(element.hasClass("plain")).toBe(true);
    })

    it("should respond to a click", function() {
        browserTrigger(element, "click");
        expect(element.isolateScope().clicked).toBe(true);
    })

    it("should update both scopes on click", function() {
        browserTrigger(element, "click");
        expect(element.isolateScope().ehSimple.message).toBe("Hello world");
    })
  })
})