Ctrl + K
DocumentationLog inGet started

tessl/npm-jest-circus

tessl install tessl/npm-jest-circus@29.7.0

The next-gen flux-based test runner for Jest that provides test framework globals and event-driven test execution

Agent Success

Agent success rate when using this tile

82%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.91x

Baseline

Agent success rate without this tile

43%

task.mdevals/scenario-1/

Email Service Notification Handler

Build a notification handler that processes email events using callback functions. The handler should accept callback functions for different email events and invoke them with the appropriate data.

Requirements

Implement a NotificationHandler class with the following functionality:

  1. Accept three callback functions in the constructor:

    • onEmailSent: Called when an email is successfully sent
    • onEmailFailed: Called when an email fails to send
    • onEmailQueued: Called when an email is queued for sending
  2. Provide a processEmail method that:

    • Takes an email object with properties: to, subject, status (one of: 'sent', 'failed', 'queued')
    • Invokes the appropriate callback based on the status
    • Passes the email object to the callback
  3. Provide a processBatch method that:

    • Takes an array of email objects
    • Processes each email using the processEmail method
    • Returns the total count of emails processed

Implementation

@generates

API

/**
 * NotificationHandler manages callbacks for email events
 */
class NotificationHandler {
  /**
   * @param {Object} callbacks - Callback functions for email events
   * @param {Function} callbacks.onEmailSent - Called when email is sent
   * @param {Function} callbacks.onEmailFailed - Called when email fails
   * @param {Function} callbacks.onEmailQueued - Called when email is queued
   */
  constructor(callbacks) {
    // Implementation
  }

  /**
   * Process a single email and invoke the appropriate callback
   * @param {Object} email - Email object with to, subject, and status
   */
  processEmail(email) {
    // Implementation
  }

  /**
   * Process multiple emails
   * @param {Array<Object>} emails - Array of email objects
   * @returns {number} Total number of emails processed
   */
  processBatch(emails) {
    // Implementation
  }
}

module.exports = { NotificationHandler };

Tests

  • When an email with status 'sent' is processed, the onEmailSent callback is invoked with the email object @test
  • When an email with status 'failed' is processed, the onEmailFailed callback is invoked with the email object @test
  • When an email with status 'queued' is processed, the onEmailQueued callback is invoked with the email object @test
  • When processing a batch of 5 emails, all callbacks are invoked the correct number of times based on email statuses @test

Dependencies { .dependencies }

jest { .dependency }

Provides testing framework and mocking capabilities.

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/jest-circus@29.7.x
tile.json