Same for when you have clear inputs and outputs. If you are writing a currency formatting function, and you know that formatCurrency(3.50, 'USD') should result in $3.50 , then go write your tests first!
Think of all the weird input you could get and how would you handle it. What if your method was called with missing arguments, like formatCurrency() ? What if a string was passed instead of a number, like formatCurrency('sorry', 'CAD') ? How would you handle those cases? What would your method do? Return undefined or null? Throw an error?
Writing your tests upfront allows you to think about all those edge cases and then helps you write your function so that it behaves properly.