I am just starting to get into unit tests but I seem to end up thinking in circles and would really like some guidance. I totally understand typical examples like how to test an adding function but my application isn't as simple.
An overview of my application (I can provide code if it will help): I have services which basically make XHR calls to my API. Each service I have so far tested it goes to the right URL, mocked responses for success and error responses and I feel pretty happy it is tested enough.
Now my controller basically calls the service, grabs the data and on success calls angular-nvd3 nv.addGraph() with some config options to draw a chart. On error it shows a toast message.
So now I am wondering what exactly do I test in this controller? This is what seems right to me but some seem impossible to test:
- service is called
- the div has a chart in it on success (is this testable?)
- a toast is displayed on failure (is this testable?)
I can check if the functions are called but the results don't seem testable to me. I can mock a response from the service call but that seems redundant to my testing on the service.
Any suggestions would really help, functions that manipulate data seem easily understandable to test but when it involves view elements or XHR requests I start getting confused as the expected success will always be accurate since it is mocked.
Thanks a bunch.
Aucun commentaire:
Enregistrer un commentaire