Gen 38:9-10

9But since Onan knew that the offspring would not be his, he spilled his semen on the ground whenever he went in to his brother's wife, so that he would not give offspring to his brother.10What he did was displeasing in the sight of the Lord, and he put him to death also.