At work I've been tasked with unit testing our Javascript code. I settled upon the Jasmine unit testing framework and began to learn how to use it when I was informed that we were now inline our Javascript code within PHP and not even using Javascript files any longer.
Can Jasmine work around this? Is there another framework that could? Should I be using a PHP unit test and a Javascript unit test? What would be my best approach?
Some example code from a fairly basic page to give you an idea:
http://pastebin.com/K3YP33id
http://pastebin.com/QaR8zUh1 <---submit
any sort of insight would be greatly appreciated
Best practice is to split all PHP out of javascript and Unit test each separately. In the long run, it becomes a nightmare to maintain and test heavily integrated code. Try a modularize as much as possible.
For example, here's how I would do it:
var exampleVariables = {
'name' = <?=$name?>,
'occupation' = <?=$occupation?>
};
unitTestableFunction(exampleVariables);
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