I am looking at how to test a knockout based website via an automated testing tool like Selenium or PhantomJS. The general flow of the tests is:
The problem is #2. Knockout updates do not occur immediately, so I do the following:
This sucks, as I either have to make the timeout long enough that knockout will always be complete, or live with spurious failures.
Is there a way that I can detect when all dependencies have been updated? Or is there another approach that I missed?
Thanks, Erick
You can attach your own subscriptions to be notified of changes to observables. Once your subscription is invoked, it can be a trigger for you to check the success condition.
For example:
myViewModel.personName.subscribe(function(newValue) {
alert("The person's new name is " + newValue);
//Person got a new name, now lets run the testing tool
});