how to mock context.targetResponse.headers in javascript spec testcases file

Hi @Dino-at-Google @Anil Sagar @ Google

i am writing unit test case for my javascript using jasmine i am unable to mock context.targetResponse.headers['x-result-count']; code snipet is var totalCount = context.targetResponse.headers['x-result-count']; test case context.setVariable("targetResponse.headers.x-result-count",3);--->does not work expect(transformResponsePayloadBusinessServices()).toBe(); expect(context.getVariable("errorJSON")).toBe(undefined); i am always getting this error when i run jasmine test cases TypeError: Cannot read property 'headers' of undefined

0 1 179
1 REPLY 1

It sounds like context.targetResponse is undefined in your test - Apigee will automatically populate these so when you run your Javascript in Jasmine (outside the scope of Apigee) you'll need to mock them.