Skip to main content

Hello, 

 

I am trying to write a unit test on a trigger that calls z.cursor and the first issue I ran into was I need to set environment variables for ZAPIER_DEPLOY_KEY after doing that I get the following error:

 

only absolute urls are supported

which is referring to z.cursor.get() . Im guessing this is due to the fact that the function is using relative pathing but I am unsure how to move forward. Is there a way to mock out this call so that the test can continue?

zapier-platform-core@8.0.1

Hi @Raman - If you’re using Jest to run your tests, try mocking the z.cursor.get and z.cursor.set functions before calling the trigger’s perform function. Here’s an example showing how I do it:

// ...

const originalPerform = App.triggerst"your_trigger_key"].operation.perform;

let cursor = "";
App.triggerst"your_trigger_key"].operation.perform = (z, bundle) => {
jest.spyOn(z.cursor, "set").mockImplementation(async (value) => {
cursor = value;
return null;
});
jest.spyOn(z.cursor, "get").mockImplementation(async () => cursor);

return originalPerform(z, bundle);
};

const response = await appTester(App.triggerst"your_trigger_key"].operation.perform, bundle);
// ...

 


@ikbelkirasan  Perfect, that solution was exactly what I needed. Thank you!