The code editor comes equipped with a quick-test environment for debugging your backend code. Functional Testing saves you the time and effort of building your own system for triggering and testing your backend functions.
To test your backend function, follow these steps:
Notes
A new tab opens in the code editor for testing your function. Your function name appears in the tab header.
In the Set Parameters section of the test tab, each parameter appears as a separate property in a JSON.Â
Note If your function does not take any parameters, the Set Parameters JSON will be empty. Just click Run without adding any arguments.
The output of your function appears on the right side of your test tab in the View Function Output section.
Your output is comprised of 4 parts:
Note When you close the test tab, the last sample parameter values you entered and the most recently generated function output are saved and will appear when you open the tab again.
You can also perform the following actions in your test tab:
You can use Functional Testing to test a variety of functions.
To test HTTP functions with Functional Testing, specify the HTTP request object in the Set Parameters section. A request template will initially be built for you including placeholder data, but you will need to edit it to fit your specific needs.
For example, when testing a post
function, you will need to replace the placeholder JSON object in the body
property with a JSON object you want to test with.
The following properties are included in the request templates:
get
and delete
functions: path
, headers
, and query
put
and post
functions: path
, headers
, and body
options
functions: path
and headers
use
functions: path
, headers
, query
, and method
Remember that HTTP Functions, even when run using Functional Testing, run with the permissions of an anonymous site visitor.
To test a function with destructured parameters, place parameter values in a JSON inside an array:
To test a function without providing all of the arguments, you'll need to set defaults for the missing arguments in the function declaration. When testing, place the arguments in an array, and leave out one or more of the arguments which have default values.
We tested the multiplyWithDefaults() function 3 times with the following arguments:
We received the following output:
To test a function containing the Javascript arguments object that accepts any number of arguments, place the arguments in an array:
To test a function with a parameter of type Date, use the following syntax with a stringified date when setting your parameter:
You can also use the following syntax:
Here's an example using the first syntax option:
And here's an example using the second syntax option: