Hi, Op. I've experienced this.
I've worked in the NHS for almost 20 years. Some 15 years ago, I'd applied for a position that I'd been covering for six months. Not to mention that, at that point, I'd done the same job, that I was applying for, for almost five years.
My manager encouraged me to go for it. But, even before I'd been told I didn't get the job, another work colleague congratulated me on this other position that I hadn't known I'd been slotted into. She was very red-faced when I told her that I hadn't heard back about whether I'd got it yet. 
To say I was confused, is an understatement. Then it dawned on me that my manager had never intended to give me that position, but had told me to go for the original job, I guess so it seemed fair.
When I asked for feedback on what I'd 'failed' on (bearing in mind, I found out later that I was the only one who had passed the written test with no faults), I was told that it was because I had young children 
At the time, I did not have the fight in me to take it any further, but I knew it was wrong. And I also knew it was based on my colour.
Some time after that, I was told of an incident (around ten years prior to me starting in the NHS) between said manager and a black employee, where the manager had been accused of racism. The outcome was the black colleague had left. But it had obviously left its mark, as everyone (except me) had known about it.
Anyway, glad to say, I am in that position now, although in a different tram. I am currently studying to work in a different field, but still in the NHS. 