CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jest-each

Parameterised tests for Jest that enable running the same test multiple times with different data sets using arrays or tagged template literals

85

1.10x
Overview
Eval results
Files

task.mdevals/scenario-6/

User Notification Service

A service that sends notifications to users via different channels (email and SMS). The service should be testable by mocking the external notification providers.

Capabilities

Sends notifications through email channel

  • When sendNotification is called with type "email", it uses the email provider and returns success status @test
  • When the email provider fails, sendNotification returns an error status @test

Sends notifications through SMS channel

  • When sendNotification is called with type "sms", it uses the SMS provider and returns success status @test
  • When the SMS provider fails, sendNotification returns an error status @test

Handles invalid notification types

  • When sendNotification is called with an unsupported type, it throws an error @test

Uses real providers when not mocked

  • When providers are not mocked, the service uses the actual provider implementations @test

Implementation

@generates

API

/**
 * Sends a notification to a user through the specified channel.
 *
 * @param {string} userId - The ID of the user to notify
 * @param {string} message - The notification message
 * @param {string} type - The notification channel ("email" or "sms")
 * @returns {Promise<{success: boolean, error?: string}>} The result of the notification attempt
 * @throws {Error} Throws an error if the notification type is not supported
 */
async function sendNotification(userId, message, type) {
  // IMPLEMENTATION HERE
}

module.exports = {
  sendNotification
};

Dependencies { .dependencies }

jest { .dependency }

Provides testing framework with module mocking capabilities.

email-provider { .dependency }

External module that sends email notifications. Exposes a sendEmail(userId, message) function that returns a Promise resolving to {sent: true} on success.

@generates

sms-provider { .dependency }

External module that sends SMS notifications. Exposes a sendSMS(userId, message) function that returns a Promise resolving to {sent: true} on success.

@generates

Install with Tessl CLI

npx tessl i tessl/npm-jest-each

tile.json