Currently, we don't have a clean way of unit testing jobs, it would be nice to have a @trigger.dev/testing package that could be used to do test job runs with mocked io and make assertions:
const jobToTest = client.defineJob({
id: "stripe-example-1",
name: "Stripe Example 1",
version: "0.1.0",
trigger: eventTrigger({
name: "stripe.example",
schema: z.object({
customerId: z.string(),
source: z.string(),
}),
}),
integrations: {
stripe,
},
run: async (payload, io, ctx) => {
await io.stripe.createCharge("create-charge", {
amount: 100,
currency: "usd",
source: payload.source,
customer: payload.customerId,
});
},
});
import { testJob } from "@trigger.dev/testing";
// Inside a test file
const testRun = testJob(jobToTest, {
payload: {
customerId: "cus_123",
source: "src_123",
},
});
expect(testRun).toHaveSucceeded();
// Test the stripe charge was called with the correct params
expect(testRun.io.stripe.createCharge).toHaveBeenCalledWith("create-charge", {
amount: 100,
currency: "usd",
source: "src_123",
});
TRI-1127
Currently, we don't have a clean way of unit testing jobs, it would be nice to have a
@trigger.dev/testingpackage that could be used to do test job runs with mockedioand make assertions:TRI-1127