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:
- Do something (e.g., click button)
- Check to see if the success side effect has occurred (e.g., span text updated)
- Repeat
The problem is #2. Knockout updates do not occur immediately, so I do the following:
- Check for success condition every 100ms
- If 5 seconds have passed, fail.
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:
More details here.