> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt ## Resource: Functional Testing Examples ## Article: Functional Testing Examples ## Article Link: https://dev.wix.com/docs/develop-websites-sdk/test-your-site/test-backend-functions/functional-testing-examples.md ## Article Content: # Functional Testing Examples With functional testing you can easily test your backend functions individually, reducing the need to build your own system for triggering and testing your backend code. You can use functional testing to test a variety of scenarios, such as functions with: - [HTTP requests](#http-requests) - [Destructured parameters](#destructured-parameters) - [Missing arguments](#missing-arguments) - [JavaScript arguments objects](#javascript-arguments-objects) - [Date objects](#date-objects) ## HTTP requests Below is an example of a function with an HTTP request that performs basic arithmetic operations based on the request path and query parameters: ![HTTP function example](https://wixmp-833713b177cebf373f611808.wixmp.com/images/227c8e658e0a6c8080faceffc2bc86a2.png) To test [HTTP functions](https://dev.wix.com/docs/develop-websites-sdk/code-your-site/build-a-custom-backend/expose-services/about-custom-site-apis.md), specify the HTTP request object by replacing the placeholder data in the request template. For example, when testing a `post` function, 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: * For `get` and `delete` functions: `path`, `headers`, and `query` * For `put` and `post` functions: `path`, `headers`, and `body` * For `options` functions: `path` and `headers` * For `use` functions: `path`, `headers`, `query`, and `method` ![HTTP function parameters showing request template](https://wixmp-833713b177cebf373f611808.wixmp.com/images/0cca5c281876f217cce53d0dd0d692af.png) ## Destructured parameters You can pull values from arrays from objects into distinct variables using destructured parameters. The following function destructures the parameters `{ factor1, factor2 }` directly from the specified object and returns their product: ![Function with destructured parameters](https://wixmp-833713b177cebf373f611808.wixmp.com/images/8af73c0908d9d2535b797f92477af386.png) To test a function with destructured parameters, place parameter values in a JSON object inside an array: ![Destructured parameters test input](https://wixmp-833713b177cebf373f611808.wixmp.com/images/86bb0558072b40ed9016c13d0b93523b.png) ## Missing arguments When you set default values in your function declarations, you can test those functions without needing to provide all of the arguments. Here is an example of a function that uses default values for `factor2` and `factor3`. ![Function with default parameter values](https://wixmp-833713b177cebf373f611808.wixmp.com/images/b7a141a0bd2f3260eb6803e967c33bf4.png) To test a function without providing all of the arguments, place the arguments in an array in the Set Parameters section, and leave out at least one of the arguments that has a default value. For example, the `multiplyWithDefaults()` function above was tested 3 times with the following arguments: * [1,2,3] * [1,2] * [1] The following results were returned: * 1 * 2 * 3 = 6 * 1 * 2 * 2 = 4 * 1 * -1 * 2 = -2 ![Default parameters test results](https://wixmp-833713b177cebf373f611808.wixmp.com/images/1e466257124ebb705bfa29cade03d391.png) ## JavaScript 'arguments' objects The JavaScript [arguments](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments) object can accept any number of arguments in a function. Here is an example of a function that uses the arguments object to find the sum of all the arguments provided. ![Function using arguments object](https://wixmp-833713b177cebf373f611808.wixmp.com/images/4d04f9d8f78b7c345fe66447409b39c4.png) To test a function containing the JavaScript [arguments](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments) object, place the arguments in an array in the Set Parameters section: ![Arguments object parameters](https://wixmp-833713b177cebf373f611808.wixmp.com/images/b3e99c359b8dcea00f4b2d2f705dff62.png) ## Date objects When working with functional testing, keep in mind that JSON has no native Date type. The following function accepts a Date object as its parameter. ![Function accepting Date object parameter](https://wixmp-833713b177cebf373f611808.wixmp.com/images/8b44555fb2f9ea139d35aa2d0e6087b9.png) To test a function with a Date parameter, specify the value as a [stringified date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toJSON) in the JSON using one of the following syntaxes: ```json { "date": { "$date": "" } } ``` ```json [ { "$date": "" } ] ``` ![Date object test parameters using stringified date](https://wixmp-833713b177cebf373f611808.wixmp.com/images/6c39a12a531c17938014b456ffc8f343.png) ## See also - [About Functional Testing](https://dev.wix.com/docs/develop-websites-sdk/test-your-site/test-backend-functions/about-functional-testing.md) - [Test Backend Functions with Functional Testing](https://dev.wix.com/docs/develop-websites-sdk/test-your-site/test-backend-functions/test-backend-functions-with-functional-testing.md)