Don’t assert return types | Jared Norman

12-Jan-2024 822
When done well, tests can serve as documentation describing how consumers of the object should interact with it. It’s not the primary goal of testing, but it’s worth considering when writing tests. What does a type assertion on the return value of our factory method tell us about the method? Not much, especially if our factory method never returns any other kind of object.Instead, the return value of the factory method should be tested for the behaviours it exposes. If we change the structure of the code later so that it returns some other kind of object, we want our tests to check that this new object works the way our consumers will expect it to. We don’t really care about its class.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle