Surah Az-Zumar 39:49
فَإِذَا مَسَّ ٱلْإِنسَـٰنَ ضُرٌّ دَعَانَا ثُمَّ إِذَا خَوَّلْنَـٰهُ نِعْمَةً مِّنَّا قَالَ إِنَّمَآ أُوتِيتُهُۥ عَلَىٰ عِلْمٍۭ ۚ بَلْ هِىَ فِتْنَةٌ وَلَـٰكِنَّ أَكْثَرَهُمْ لَا يَعْلَمُونَ
And when adversity touches man, he calls upon Us; then when We bestow on him a favor from Us, he says, "I have only been given it because of [my] knowledge." Rather, it is a trial, but most of them do not know.
Translation: Saheeh International
Tafsir
So when some distress befalls man al-insān here a generic he supplicates Us. Then when We bestow on him a grace from Us he says ‘I was given it merely by force of knowledge’ from God that I was deserving of it. Nay but it this saying is a trial a test by which servants are tested. …
Excerpt from Tafsir al-Jalalayn, commentary on 39:49, via Quran.com. The reader has the full commentary and 9 more tafsirs.