JavaScript Function Testing with Error Handling