When writing qUnit, it often gets hard trying to simulate an ajax operation.
I have written a short helper to allow us to test async.
How does it work?
Imagine you have a very simple bit of code that shows results from the data set
Now we should be writing qUnit tests to assert that it works in all scenarios.
Here are two such tests:
As you can see, we can mock out data request really easily with the style of data service. You simulate an existing Data service and get reliable output so you can test every scenario. This means there is no excuse to write code for if your data services fail to return with a success message - it’s a very simple task to write code to test for the failing data service scenarios.