What to use to refactor the javascript / jQuery of a web application to use require.js and jasmine

admin

Administrator
Staff member
I hope this question is not too general, but i haven't found any good tutorial on how to do the transition from standard javascript / jQuery code to modular / tested code.
Mmy new task is the complete refactoring of the javascript of our wordpress plugin.
Our current code is standard jQuery code, thrown all into a file, with checks on the existance of dom elements to understand on what page we are in and attach the correct event handlers.
My goal is simply to write more manteinable and clear code, and introduce tests in the process.
My approach would be:

<ul>
<li>Try to modularize code in separate files (one file for each page) and use require.js to load only the required code.</li>
<li>write some tests with jasmine/sinon and try to adapt the esisting code so that the tests pass</li>
</ul>

Have you got any other suggestions/best practice?
Can you share some example on how you approached similar tasks?<br>
I was thinking about bringing in an mvc framework but if i can stick to standard jQuery code i think it's easier for the development team because it doesn't add complexity