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

API Reference

Jake edited this page Dec 15, 2020 · 10 revisions

afterEach(fn)

Runs a function after each test in the context it was called in.
If the function is async, petzl will wait for the function to finish before continuing.

const { it, describe, afterEach, assert } = require("quyz")

const database = createDatebase();

afterEach(() => {
    database.clear()
});

it("should insert a user", async () => {
    const response = await database.insert({ name: "bob", id: 1 });
    assert(response.success);
});

it("should find all users", async () => {
    const users = await database.find();
    assert.strictEqual(users.length, 0);
});

Note: If the bubbleHooks option is set to true, beforeEach and afterEach will be called after each test in it's own context and any tests in child contexts, but not in parent contexts.

beforeEach(fn)

Runs a function before each test in the context it was called in.
If the function is async, petzl will wait for the function to finish before continuing.

const { it, describe, beforeEach, assert } = require("quyz");

const database = createDatebase();

beforeEach(async () => {
   database.clear()
   await database.insert({ user: "bob});
});

it("should insert a user ", async () => {
    await database.insert({ name: "billy", id: 2 });
    const users = await database.find();
    assert.strictEqual(users.length, 2);
});


it("should find all users", async () => {
    const users = await database.find();
    assert.strictEqual(users.length, 1);
});

describe(title, fn)

Groups together related tests, also creating a new hooks context.
Unlike many other testing frameworks, describe blocks can be asynchronous, meaning that tests can be defined asynchronously.

const { it, describe, assert } = require("quyz")

// Sync
const dogs = [
    { name: "buddha", cuteness: 10 }, 
    { name: "buddy", cuteness: 9 }
];

describe("my dogs", () => {
    it("should check if they're all home", () => {
        assert.strictEqual(dogs.length, 2);
    });
   
    it("should make sure they're cute", () => {
       for (const dog of dogs) {
           assert(dog.cuteness > 8);
       }; 
    });
});

// async

describe ("dogs", async () => {
    const dogData = await fetch("https://dog.ceo/api/breeds/image/random");
    
    it("should have returned success message", () => {
        assert.strictEquals(dogData.status, "success");
    })

});

it(title, fn

Runs a function that either passes (does not throw an exception) or fails (throws an exception).

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

it("should confirm math is real", () => {
    assert(1 + 1 === 2); 
});

// You do not need to use 'assert', you can use any assertion library, or none!

// chai

it("should confirm math is real", () => {
    expect(1 + 1).to.equal(2); 
});

// unexpected

it("should confirm math is real", () => {
    expect(1 + 1, "to be", 2);
});

// none
it("should confirm math is real", () => {
    if (1 + 1 !== 2) {
        throw new Error("The simulation is broken");
    }
});
Clone this wiki locally