The story of Jehoshapaht reads much like that of his father Asa. The Lord was with him and greatly prospered him because he walked in the first ways of his father David, seeking the Lord and not Baalim (2 Chronicles 17:3-5).
Because his heart was lifted up in the ways of the Lord, he took away Judah's groves and high places and sent itinerant priests throughout all the cities of Judah to teach the people God's law (2 Chronicles 17:6-9).
When invaded by Moab, he prayed to the Lord, proclaimed a fast throughout all Judah, and depended on God to grant a miraculous victory (2 Chronicles 20:1-25).
But...In chapter 18, he joins affinity with Ahab, agreed to go to battle with him at Ramoth-gilead despite the warnings of God's prophet Micaiah, and even allowed Ahab to convince him to put on his clothes so the Syrians would think he was the king of Israel. Not real sure what he was thinking.
He was rebuked for this by Jehu (not the king of Israel, the prophet, the son of Hanani, who rebuked Jehoshaphat's father Asa) in chapter 19, but in chapter 20 he joined himself with Ahab's son Ahaziah – who did very wickedly the Bible says – in a shipping venture that God (literally) broke up.
Now, when you simply view the lives of Asa and Jehoshaphat you can recognize their error and you can see how certain things would've turned out better had they separated themselves from the kings and peoples of the surrounding nations. But to tell the truth, it doesn't seem like their ungodly alliances cost them all that much.
But such thoughts quickly fade when you continue your reading in 2 Chronicles 21-22. Jehoshaphat, the one who joined affinity with Ahab, had a son named Jehoram (the same name as one of Ahab's sons) who killed all his brethren, married one of Ahab's sisters, Athaliah, and led the nation into the pagan worship practiced by the wicked kings of Israel. All but one of his sons were carried away by the Philistines and Arabians, and he died a slow and painful death of sore diseases (after 2 years, his bowels fell out). The Bible says he departed without being desired.
Not only that, but when his youngest and only remaining son Ahaziah died, his wife Athaliah massacred all of her grandchildren (or so she thought – Joash's aunt hid him in a bedchamber) and took the throne over Judah.
So in hindsight, Asa's and Jehoshaphat's ungodly alliances cost much more than they could have ever imagined. And that's always the case with sin. Our problem is that we're so short sighted. We think that we're OK because what we're involved in isn't hurting us right now. But that's just not the case. You always reap what you sow. You always reap much more than you sow. And sometimes you reap much later than you sow.
Galatians 6:7-8 Be not deceived; God is not mocked: for whatsoever a man soweth, that shall he also reap. For he that soweth to his flesh shall of the flesh reap corruption; but he that soweth to the Spirit shall of the Spirit reap life everlasting.