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?
Either attach DOM when running test or mock the document.querySelector and angular.element in case you don't need the same.
Remember to remove mock/spy on angular element after test is completed as it will interfere with the jasmine framework which uses that internally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With