You talk to the villager few times on EVERY ROOM in your house. They will eventually come to the conclusion that they must leave.
If you leave your house before they do, they will not give you a present I think.
But if you?re best friends with a villager, and they visit your house without notice, you keep talking to them in the same room and wait for a while until they decide to leave. There is an instance when they visit and you?re not in the main room of your house. They will wonder where you are and if you dont go to the room for quite a while, they will automatically leave.
The same rule applies, they will not give you a present if you leave before them.