I struggle with the idea of being joyful during trials. I know James said, "Consider it all joy, my brethren, when you encounter various trials, knowing that the testing of your faith produces endurance. And let endurance have its perfect result, so that you may be perfect and complete, lacking in nothing" (James 1:2-4), but I have a hard time doing this.
James is telling to find joy in the outcome of trials, though the trial itself is not pleasant. "All discipline for the moment seems not to be joyful, but sorrowful; yet to those who have been trained by it, afterwards it yields the peaceful fruit of righteousness" (Hebrews 12:11). In other words, after the trial is over, how do you categorize it? Do you moan and grumble that you had to go through with it? Or, while you admit it wasn't fun at the time, do you look back and are glad that you experienced it because it made you into a stronger Christian?
The Greek word hegeomai has two sets of meaning: 1) lead or guide, 2) think, consider, esteem, or count. What you count something to be is not always what that thing actually is.
"By faith Moses, when he had grown up, refused to be called the son of Pharaoh's daughter, choosing rather to endure ill-treatment with the people of God than to enjoy the passing pleasures of sin, considering the reproach of Christ greater riches than the treasures of Egypt; for he was looking to the reward" (Hebrews 11:24-26).
The reproach of Christ is not wealth, but Moses counted it as a greater treasurer than all the wealth of Egypt.
"I thank Christ Jesus our Lord, who has strengthened me, because He considered me faithful, putting me into service, even though I was formerly a blasphemer and a persecutor and a violent aggressor. Yet I was shown mercy because I acted ignorantly in unbelief; and the grace of our Lord was more than abundant, with the faith and love which are found in Christ Jesus" (I Timothy 1:12-14).
Paul's earlier life was not exemplary of a faithful servant to Christ; yet, Jesus was willing to count his past differently. This led to Paul's deep appreciation of the grace extended to him. From a worldly standpoint, Paul's past life was that of a devote Pharisee and perhaps a position one day on the Sanhedrin Cout. But Paul said, "But whatever things were gain to me, those things I have counted as loss for the sake of Christ. More than that, I count all things to be loss in view of the surpassing value of knowing Christ Jesus my Lord, for whom I have suffered the loss of all things, and count them but rubbish so that I may gain Christ" (Philippians 3:7-8). As valuable as his past life might have been, Paul now considers them to be trash in comparison to what he has in Christ.
I think James is speaking of trials in the same fashion. However difficult they might have been, when you see the outcome, the trials can be categorized as a joy because of what it produced.