Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

In my code there's a line:

var contentWidth = angular.element(document.querySelector('.content'))[0].clientWidth;

It works fine when running the app but when unit testing I get error:

TypeError: 'undefined' is not an object (evaluating 'angular.element(document.querySelector('.content'))[0].clientWidth')

How to solve this issue?

share|improve this question
    
Guessing this is because there is no DOM built when running your unit test. Try building a mock DOM with the elements you need. –  pje Aug 12 '14 at 13:24
    
Not really clear on how to do that... –  Julius Aug 13 '14 at 10:37
    
Did you attach your compiled element to the document? Otherwise, document.querySelector() won't be able to find it. –  Thomas Sep 9 '14 at 15:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.