Is it good to thank Allah for an unanswered dua, in the trust that he will answer it? To act as if it has already been given

One should always thank Allah, because whether it is answered or not God knows what’s best for us.