Step 5: Writing a Test Function

While not technically required, we highly recommend that you write a test script for your function. Before you upload a function to Yext you will want to test it locally to make sure it works as expected. Deno has testing built into the framework.

Let’s fill out the test.ts file:

import { myFunction } from "./mod.ts";
import { assertEquals } from "https://deno.land/std@0.114.0/testing/asserts.ts";

Deno.test("Test My Function", () => {
 const input = "hello";
 const output = myFunction(input);
 assertEquals(input, output);
});

In this test named (“Test My Function”) we are testing whether the input and the output are the exact same. Since Deno has testing built in you can just run

deno test

And it will automatically run your tests. If you are using VSCode there is also a handy “Run Test” button right in the editor! vsCode

Feedback