Any examples of or advice for unit testing a viewModel?

2,644 views
Skip to first unread message

Richard Lowe

unread,
Jun 19, 2011, 4:56:24 PM6/19/11
to KnockoutJS
Slowing learning Knockout with ASP.NET MVC3/Razor and since I notice
there is so much more important code going into my client side now, I
wonder if anyone has examples and recommendations for doing JavaScript
based unit testing of my viewModels and templates?

Does anyone use a JavaScript test framework with their knockout code?
Either one that incorporates Knockout.js as part of the tests (i.e. to
make sure you're fulfilling the conventions for knockout etc) or just
tests the viewModels and templates around it? I would love to hear any
advice you have around this topic!

Thanks,
Richard

rpn

unread,
Jun 20, 2011, 1:00:13 AM6/20/11
to knock...@googlegroups.com
Hello Richard-

Knockout itself uses JSSpec to run a suite of verifications.  You can see the tests here: https://github.com/SteveSanderson/knockout/tree/master/spec  or see them run here: http://knockoutjs.com/spec/runner.html

I have not done a ton of JS unit testing myself, but have used QUnit before.  If you write your Knockout code in a such a way that your view depends on your view model, but not the other way around, then you can first write a nice set of tests against your view model directly without a UI.  After that, then I think that it is helpful to both verify that your UI responds appropriately to actions on your view model and that your view model appears correct based on actions made in the UI.  


Would definitely be interested to hear what others are doing as well.

Toby Evans

unread,
Jun 20, 2011, 5:58:38 AM6/20/11
to knock...@googlegroups.com
Hi,

try this: http://code.google.com/p/js-test-driver/

what makes this great for us is that it can product the jUnit.xml we
need to break a build in a CI server, vital for a team project

T

--
http://2cheap2meter.blogspot.com/
http://communergy.codeplex.com

Reply all
Reply to author
Forward
0 new messages