Tuesday, October 25, 2011

Tue 25th October

Late one last night so late start today. Things are starting to take shape.

It’s all working quite nicely. Now writing a crapload of unit tests. Got to start looking at mocking in JavaScript.

A few tests now written, including some against the navigation pubsub stuff. Works out alright! Haven’t tested most of the navigation module as the meat is in private functions and the output is manipulation of the DOM using jQuery. Two potential approaches – mock jQuery so we can ensure the right calls are made, or render the actual HTML in the test, allow navigation to manipulate and test the resulting changes to the DOM, more like an integration / functional test. Oh… A third option is to make the methods in question public.

I intend to investigate both. The latter is probably easier in some ways and I intend to do this anyway at some point. A problem with this is getting the jQuery templates (or knockout templates / control flow bindings – more on this in a sec) into the QUnit test fixture, without copy and pasting them. They can be loaded by AJAX fairly simply, but QUnit won’t be run from a web server. Trying to load the from a local file but running into cross-domain issues. There may be some hacks to allow this - http://stackoverflow.com/questions/4208530/xmlhttprequest-origin-null-is-not-allowed-access-control-access-allow-for-file).

Since jQuery templates are being discontinued, I’ve also been looking at knockout control flow bindings. This should allow me to do away with an external templating solution and also enables the template to be written as a single template, rather than a separate, small template wherever a foreach is used. Should be much more elegant!

Enough for now. ZZZzzzZZzzzzzzzZzzzzzz…zzz….z………z……

No comments:

Post a Comment