@headstone, your brain has various sections (lobes) that carry out different functions. The brain stem is at the base of the brain and consists of the medulla oblongata, the midbrain (mesencephalon) and the pons. The medulla oblongata helps regulate breathing, heart and blood vessel function, digestion, sneezing, and swallowing. The midbrain (mesencephalon) controls motor movement, particularly movements of the eye, and auditory and visual processing. The pons forebrain to the cerebellum, along with nuclei that deal primarily with sleep, respiration, swallowing, bladder control, hearing, equilibrium, taste, eye movement, facial expressions, facial sensation, and posture.
So, when the tests are done that check all of the nerves that control all of these functions, and they all fail, it tells the doctors that there is no function in the any of those three areas of the brain stem which is vital to the preservation of life.
The reason the heart still beats for a time is that the heart contains cells that are myogenic - they can incite their own heart beat within the cell to create a contraction of the heart - they don't need a message from the brain to get the heart beating.