Sinon testing lib is handy to mock the global scope variables.

Here's example of using sinon.sandbox

import { assert } from "chai";
import * as sinon from "sinon";
import * as someLib form "some-lib";

import { methodThatUseSomeMethod } from "./somefile";


context("Some test case", () => {
	const sandbox = sinon.sandbox.create();

	before(() => {
		sandbox
			.stub(someLib, "methodName")
			.returns("mock value");
	});

	it("should do testing", async () => {
		const res = methodThatUseSomeMethod();
		assert.equals(res.someField, "mock value");
	});

	after(() => {
		sanbox.restore();
	});
});