You must listen on the global message event of the window object, but you can filter the source iframe using the source property of MessageEvent.
Example:
const childWindow = document.getElementById('test-frame').contentWindow;
window.addEventListener('message', message => {
if (message.source !== childWindow) {
return; // Skip message in this event listener
}
// ...
});