I am cruising through a situation where I am my own backend and fronend developer.
Let's say I have a basic backend API with some call /register/{area}
.
The {area}
piece is dynamic and can change. Now I have a nice frontend application in angular that provides a selection of various area
entries, Let's say they can be "A" and "B".
My backend already has test cases that ensure that the API does not execute /register/C
because C would not be valid. So the API guards itself against misuse.
But what's about the frontend? The frontend allows you to pick A or B from a list and executes some javascript code that calls the API above.
The frontend tests verify that you can pick A or B and that the logic executes the proper call to a mocked backend, handles normal responses and error responses, etc.
But a question arose whether I also should test what happens when the user magically selects the invalid value C.
Should I write a frontend test for that? Let's say the frontend has a method called registerForArea(area)
. There is no path from the UI to actually call registerForArea('C')
because no normal control flow results in this path.
But in a frontend unit test I of course can verify certain behaviour by manually calling registerForArea('C')
, but should I? Remember, the backend call is tested.
I tend not to do it, because testing a path through the frontend that can usually never occur is like testing non public APIs. Sure, never trust the user but facilitating a situation that only misuse would cause opens endless permutations of the question what if the user meddles with parts of the JS which I regard as useless as one has no control over what a user can do in the frontend.
Very interested in other point of views or confirmation of my bias :)
/register/C
is an URL that the user could enter in their address bar, then yes you should test for that./register/C
also for/register/A
//B
if those areas become invalid? This doesn't actually sound impossible. Just mock your backend to do that, without adding an unreachable selection forC
. Treat it as "handling normal error responses".