Ubasses' response is too simplistic.
>>> "If the beneficiary dies after the testator then their heirs inherit"
. . . but ONLY when the intended beneficiary was the son or daughter of the testator (and ONLY when that beneficiary had surviving issue. i.e. children or grandchildren - the gift can't pass to any other relative, such as to the deceased beneficiary's wife).
If the gift was made to someone who was not a child of the testator (or if that child had no surviving issue) the gift 'fails' and forms part of the residuary estate. It will then pass to the residuary beneficiary, if there is one. (i.e.if the will states "Everything else I leave to Fred Bloggs", then it will be Fred who receives the gift).
Where the is no residuary beneficiary named in the will (or otherwise implied by its provisions), or if it is actually the residuary beneficiary who pre-deceases the testator, a 'partial intestacy' is created and the gift must be distributed in accordance with the rules on intestacy.
[Wills Act 1837]
The foregoing assumes that the will doesn't make provision for such circumstances. Any well-drafted will should always clearly state what should happen to a gift under that will if the beneficiary pre-deceases the testator. Then it will be the provisions of the will, rather than the rules I've outlined above, which will apply.