Skip to content
This repository was archived by the owner on Jul 3, 2025. It is now read-only.

Recipes

Jake edited this page Nov 30, 2020 · 1 revision

Macros

For writing tests with shared logic, use the macro pattern.

const { it } = require("petzl");
const assert = require("assert");

function myMacro(input, expected){
   assert.strictEquals(input, expected);
}

it("should confirm 2 + 2 = 4", myMacro, 2 + 2, 4);
it("should confirm 3 + 3 = 6", myMacro, 3 + 3, 6);

You can also dynamically generate titles with Title Functions

const { it } = require("petzl");
const assert = require("assert");

function myMacro(input, expected){
   assert.strictEqual(eval(input), expected);
}

function myMacroTitle(input, expected) {
   return `should confirm ${input} = ${expected}`
}

it(myMacroTitle, myMacro, '2 + 2', 4);
it(myMacroTitle, myMacro, '3 + 3', 6);

Clone this wiki locally