I was in a similar situation once. It hurt my pride and offended me that the boss thought I was good enough to train the new guy but not to promote. It was a wake-up call to me. I started looking for a new situation.

I helped the new guy, did a little basic record-keeping of what I did to orient him to local procedures, and took a while to work through being kind of miffed by the situation. I resolved to leave and felt good about that.

I identified what kind of work and environment I wanted next, took about a year to get some training and new skills, and started networking to meet people. It was the first time as an adult that I looked for a job while I still had one. This gave me the financial security to pass on one fair offer with only slightly better pay until I got a really good offer from a much better company. By then I was leaving for me rather than because of the old boss or company, but I will admit to a petty enjoyment in the shock on my boss's face when I gave notice I would be leaving.

By the way, some of the reasons why I was passed over were legitimate and to this day I'm still somewhat weak in a couple of those areas.

In hindsight, being passed over was a good thing for me because it raised my discomfort level and awareness so that I was motivated to improve my situation.

I wish you all the best.