Testing
Use the SDK in your test suite to verify webhook integrations end-to-end. Create temporary endpoints, trigger your application, and assert on the captured requests.
Pattern: test, assert, cleanup
import { WebhooksCC } from "@webhooks-cc/sdk";
import { describe, it, expect, beforeAll, afterAll } from "vitest";
const client = new WebhooksCC({
apiKey: process.env.WHK_API_KEY!,
});
describe("payment webhooks", () => {
let endpoint: Awaited<ReturnType<typeof client.endpoints.create>>;
beforeAll(async () => {
endpoint = await client.endpoints.create({
name: "test-payments",
});
});
afterAll(async () => {
await client.endpoints.delete(endpoint.slug);
});
it("sends a webhook on successful payment", async () => {
// Trigger your application with the endpoint URL
await processPayment({
webhookUrl: endpoint.url,
amount: 4999,
});
// Wait for the webhook to arrive
const request = await client.requests.waitFor(endpoint.slug, {
timeout: 5000,
match: (r) => r.method === "POST",
});
const body = JSON.parse(request.body!);
expect(body.event).toBe("payment.success");
expect(body.amount).toBe(4999);
});
});CI/CD integration
Add your API key as a secret in your CI environment. Example GitHub Actions config:
# .github/workflows/test.yml
env:
WHK_API_KEY: ${{ secrets.WHK_API_KEY }}
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm testUsing waitFor
The SDK includes a built-in waitFor method that polls until a matching request arrives:
// Wait for any request
const req = await client.requests.waitFor(endpoint.slug);
// Wait for a POST with a specific body
const req = await client.requests.waitFor(endpoint.slug, {
timeout: 10000,
pollInterval: 500,
match: (r) => {
if (r.method !== "POST") return false;
const body = JSON.parse(r.body ?? "{}");
return body.event === "order.created";
},
});Tips
- Use unique endpoint names per test run to avoid conflicts in parallel CI
- Always clean up endpoints in
afterAll/afterEach - The free plan supports 200 requests/day — enough for most test suites
Framework examples
- Stripe + Vitest - payment webhook assertions
- GitHub + Jest - push event verification
- Playwright E2E - browser flow + webhook assertions