Genesis 38:9

ISV(i) 9 But Onan knew that the offspring wouldn’t be his own heir, so whenever he had sexual relations with his brother’s wife, he would spill his semen on the ground to avoid fathering offspring for his brother.