What are you calling a real API ? Do you mean a third party API ?
If yes, I write 2 types of tests :
-
a first test where I only inject the data with the same format as the one coming from the API, you can effectively mock the function from which you call the API
-
a second test in real conditions where I don't mock the function and where I really use the API, but according to me this test is less important than the first one