ReferenceError: Request is not defined

Hello,

I am using a Javascript policy to make multiple calls to different proxies. I am moving off of Hosted Targets.  Everything is working as I would expect, however I need to write some Jasmine unit tests.  I am getting the 'ReferenceError: Request is not defined' when running my specs. The line causing this is 

var myRequest = new Request();

What do I need to import in order for my spec file to work? The documentation just says that the httpClient Object is exposed. Thanks! 

0 1 1,086
1 REPLY 1


@needhelp123 wrote:

I am getting the 'ReferenceError: Request is not defined' when running my specs.


Just to clarify, the error you are seeing is in the test spec file.  It happens when you run the test.  It's not code that is part of the API Proxy. Is that correct?


@needhelp123 wrote:

The documentation just says that the httpClient Object is exposed.


The documentation that would discuss the httpClient would be documentation for the JS callout.  If you are trying to test your API proxy, then you will not be running that test code within the API Proxy.  It will be outside the proxy, and it will have different objects and scope, etc. A different runtime. 

If you want to unit test just the JS code within the API proxy, then you need a mock framework to help you do that.  Here is an example