Best answer

Issues writing unit test for z.cursor

  • 24 June 2021
  • 2 replies

Userlevel 1



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?



Best answer by ikbelkirasan 24 June 2021, 19:42

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

2 replies

Userlevel 7
Badge +12

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.triggers["your_trigger_key"].operation.perform;

let cursor = "";
App.triggers["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.triggers["your_trigger_key"].operation.perform, bundle);
// ...


Userlevel 1

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