I have a bunch of test cases for various Angular directives (1.4.7), and I use Karma, Jasmine and Sinon for testing.
I am trying to add unit test for a new directive, which is the only directive in which I am currently using $window , but I see a cryptic error in the console output:
TypeError: 'undefined' is not an object (rating 'this.proxy.toString')
This error comes from sinon.js on line 2372.
I do all the βnormalβ things in the unit test directive, for example, creating a fake element with the directive as an attribute:
testElement = document.createElement('div'); testElement.setAttribute('data-my-directive'); document.body.appendChild(testElement);
And compilation of the directive:
$compile(testElement)($scope);
I use $provide to try the mock $window object:
module('app', function ($provide) { $provide.value('$window', { id: 'test' }); });
But as soon as I try to use $window in the test file, the error shown above is thrown.
As I said, I have a bunch of other unit tests for other directives, services, and controllers working as expected, so everything seems to be configured correctly. This is exactly this test.
Any ideas?
javascript angularjs karma-runner sinon
danwellman
source share