Published on February 11, 2013 by Toran Billups
I recently finished a small handlebars project and found that despite the logicless approach, you might need to write your own helper to accomplish something the library does not offer by default.
For example, out of the box the if statement allows you to say if something is defined or undefined. Beyond this you can't directly compare attributes on the object being passed in.
Lets assume for the moment you need this feature (for better or worse). You can extend handlebars by writing your own helper.
Before this moment I didn't have much of a need to unit test my templates directly because they were essentially logicless. But this if /equal template is a clear violation of that idea and should have some testing around it to understand how it works / verify it still works when we change it / etc.
I decided to write a simple jasmine unit test that would prove the conditional works as expected. I have verified this unit test works with both the jasmine-node and jasmine-phantom-node test runners. If you want a full blown example of the jasmine-phantom-node version you can find it in the examples directory.
Hopefully the example above will get someone else unit testing their handlebars templates!