For those testers of Objective-J, there are difficulties testing Cappuccino. One particularly sticky area is Views. Unit testing these suckers is impossible because the DOM doesn't exist in OJUnit. Not true! We can actually use OJMoq to subvert (oh we're sneaky!) the Views and make them think that they are talking to the DOM.

Note/Disclaimer: I'm not saying that everyone should use this method of testing. In fact, views should be in the form of CIBs and real testing should be with the usability of the product. Put the logic in the Controllers and test those! This is just a "because we can" post and you'll note that I never use it in OSL to test views.

So, I'm going to drop a big view file on top of you. You can really just ignore that, but pay attention to the OLFeedbackWindowTest.j file. It's small but contains important information.

[gist id="237044"]

You'll notice the two lines

CPApp = moq();
CPApp._windows = moq();

at the beginning of that test file. They are what allow us to subvert the views. Two lines and previously untestable areas of your code are now testable! Good luck testing, people!