Small js snippets for templates

My current problem is that I want to add small JS functions to my templates. My current design solution is to append to the bottom of the .hbs template the JS script. Such as the one below.

However, this causes a lot of problems when I make my unit tests and I was wondering if there is a better design solution.

I currently thought is to make a small file in my vendor dir and import the files. But I cannot seem to get it to work. Any guidance would be much appreciated.