 Matthew and John, who were apostles, Mark and Luke, who were not apostles, but who learned it from other people, they would have learned this directly from Jesus. So he would have told them, when I was in the desert, here's what happened. The second way they knew was by the inspiration of the Holy Spirit, who revealed it to them as they were writing those scriptures.