2.3.23 • Published 5 months ago

@systemfsoftware/trigger.dev_testing v2.3.23

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Trigger.dev Testing Package

The testing package provides useful helpers to write your own tests in jest and vitest with complete type support.

Usage

  1. Install the package:
# npm
npm install -D @systemfsoftware/trigger.dev_testing

# yarn
yarn add -D @systemfsoftware/trigger.dev_testing

# pnpm
pnpm add -D @systemfsoftware/trigger.dev_testing
  1. Import the package in a test as follows:
import { toHaveSucceeded, createJobTester } from "@systemfsoftware/trigger.dev_testing";
import { expect, vi } from "vitest";

expect.extend({ toHaveSucceeded });
const testJob = createJobTester(vi);
  1. You can then use it like this:
const jobToTest = client.defineJob({
  id: "test-job",
  name: "Test Job",
  version: "0.1.0",
  trigger: eventTrigger({
    name: "test.trigger",
  }),
  integrations: {
    dummy,
  },
  run: async (payload, io, ctx) => {
    return await io.dummy.doSomething("test-task", {
      foo: payload.foo,
    });
  },
});

const testRun = await testJob(jobToTest, {
  payload: {
    foo: "bar",
  },
  tasks: {
    "test-task": {
      bar: "baz",
    },
  },
});

// job run was successful
expect(testRun).toHaveSucceeded();

// task was called exactly once
expect(testRun.tasks["test-task"]).toHaveBeenCalledOnce();

// task was called with correct params
expect(testRun.tasks["test-task"]).toHaveBeenCalledWith({ foo: "bar" });

// mocked task output was correctly returned
expect(testRun.tasks["test-task"]).toHaveReturnedWith({ bar: "baz" });

// job run has expected output
expect(testRun.output).toEqual({ bar: "baz" });

More information

See the official Trigger.dev Unit Testing Reference for a working setup with Vitest.

License

MIT

2.3.23

5 months ago

2.3.22

5 months ago

2.3.19

6 months ago

2.3.20

6 months ago

2.3.21

6 months ago

2.3.19-beta.0

10 months ago