I’m just getting started with Knockout JS and with QUnit for doing unit tests of my knockout view model. The problem that I’m running into is that if I have multiple tests in my qunit test javascript file, and I link to a javascript file which includes my View Model definition… any changes that I make to the View Model in one test are also present when I start the next test in the test module. I’m used to have an NUnit environment where my state is cleared automatically between tests.
Is there a method, pattern or example that someone can point to which shows the best way to define a view model, and have it reset it’s state for the start of each unit test?
Are you using the second parameter (lifecycle) of
module? If not, you should be able to instantiate your view model at this level, something like:From what I remember reading, QUnit tets are run in the same scope as
setupandtearDown, so any members defined insetupwill be accessible within any subsequent tests.