When creating a mockrequest the following way:
const { req } = createMocks({
method: "POST",
body: "someBody",
headers: { "Referer" : "someReferer" },
});
const response = await handlerUnderTest(req);
the request handler under test cannot use Headers.get from the standard. This is needed when for example mocking NextRequest, because it is heavily based upon that Web Request API standard, it just extends it a little.
This happens because inside createRequest the headers object gets passed directly into the mock requestobject here.
There is a workaround by monkeypatching the getter onto the mockRequest after creation:
const { req } = createMocks({
method: "POST",
body: "someBody",
});
req.headers.get = () => "somereferer";