Effectively the unit test AngularJS directive that manages the DOM

I am working on a simple directive with AngularJS to add a smooth scroll effect to any link.

I published my work here: https://github.com/arnaudbreton/angular-smoothscroll Everything works in a real context, but I cannot figure out how to do a unit test. I wrote a test that cannot pass because $window.pageYOffset not increasing as expected.

Thank you for your help!

+4
source share
1 answer

I made a pull request that makes your tests work. https://github.com/bennyjo/angular-smoothscroll/commit/e660a8e1a4497907a9c74d9e359f2bbfa0b8326c

The main problem was that there was no place where you could scroll the window. Therefore, scrolling was not possible, and the tests failed. I added some height to the body element to make a scrollable window.

 $('body').height(window.innerHeight*2).append @target 

I also reset the scroll position before each test. If we do not, the second test will fail.

 window.scrollTo(0, 0); 
+1
source

Source: https://habr.com/ru/post/1484528/


All Articles