In Jest, how can I mock a global function that’s not part of any module?

My HTML loads a 3rd party Javascript lib that is not part of any module: it’s simply a global, loaded via <script src="https://3rdparty/theirlib.js">. I have no control over that code.

I would like to unit test with Jest and mock out this 3rd party code. Jest has great docks how to mock out imports and modules – this code isn’t importable. How can I mock it?

Note: The posts here and here are related but do not address this.