← View all announcements
New release
New release
New release
Oct 12, 2023

Run mode injected into the hook's context

During test runs of your hook, you might not want to call live API endpoints but development endpoints instead.

Your hook code can now detect whether it's called in live or test mode.
You can use the isTestMode property of the hook's context to distinguish between run modes.

Here is an example about using a different API endpoint depending on the run mode:

module.exports = async function (payload, actions, context) {
  const api = context.isTestMode ?
    'https://dev.myapi.com' : 
    'https://myapi.com';

  const { data } = await actions.http.post(api, { a: 1 });
}