I'm asking myself how verbose I should be when unit testing projects written in untyped languages like Javascript
.
Let's take an example for a strongly typed language (C#
)
public bool Foo(MyClass myClass) { /* ... */ }
As C#
is strongly typed I can be sure that myClass
is either null
or an actual instance of MyClass
(or any instance of a subclass if possible) so my testable values are just these.
Now let's port this method to Javascript
:
function foo(data) { /* ... */ }
Now I can't be sure what type data
is of as it could be anything.
Inside foo
I can check which type data
has but to ensure that the function works even with invalid types I would have to test all possible types in my unit tests which produces a lot of extra code.
This topic really bothers me especially in untyped languages where I cannot determine the actual type just by looking at the code. On the one hand I don't want to write a whole lot of code to test every possible type. On the other hand I feel like I'm missing something if I test just the types I'm expecting.
Are there any general recommendations or best practices for this problem?