Unit test $window resize method
<p>I have the following code in a simple directive link function which checks for a window resize and calls a function.</p>

<pre><code>return {
    restrict: 'A',
    link: function (scope) {
        angular.element($window).on('resize', function() {
            scope.getSize();
        });

        scope.getSize() = function() {
            return true;
        };
    }
}
</code></pre>

<p>I'm trying to test on <code>($window).on('resize')</code> that <code>scope.getSize()</code> is called.</p>

<p>In my tests I compile my directive like so:</p>

<pre><code>beforeEach(inject(function($rootScope, $compile, _$window_) {
    $window = _$window_;
    $scope = $rootScope.$new();
    element = angular.element('&lt;div data-watch-resize&gt;&lt;/div&gt;');
    element = $compile(element)($scope);
    $scope.$digest();
}));
</code></pre>

<p>I then spy on the resize function of window, and expect the function to have been called</p>

<pre><code>spyOn($window, 'resize');
$window.innerWidth = 1026;
$scope.$digest();
expect(element.scope().getSize()).toHaveBeenCalled();
</code></pre>

<p>however i get the following error </p>

<p><code>Error: resize() method does not exist</code></p>

<p>I'm not really sure why it doesn't exist, is there something obvious I am doing wrong?</p>