Parameterised tests for Jest that enable running the same test multiple times with different data sets using arrays or tagged template literals
85
A test suite for user profile generation that validates profile data structures with snapshot testing while handling dynamic fields.
The user profile generator creates profiles with both static and dynamic fields. Tests must validate the entire structure while accounting for fields that change between test runs (timestamps, IDs, tokens).
Given a generated user profile with name "Alice Smith" and role "admin", verify the complete profile structure matches the expected snapshot, treating createdAt as any Date, userId as any String, and sessionToken as any String @test
Given a generated user profile with name "Bob Jones" and role "user", verify the complete profile structure matches the expected snapshot, treating createdAt as any Date, userId as any String, and sessionToken as any String @test
User profiles contain nested address and preferences objects with some fields that are static and others that are dynamically generated.
Given a user profile with an address containing a generated geocode object (with dynamic latitude/longitude) and a static city/country, verify the profile snapshot treats geocode.latitude as any Number, geocode.longitude as any Number while keeping other address fields exact @test
Given a user profile with preferences containing a lastModified timestamp and static theme/language settings, verify the profile snapshot treats preferences.lastModified as any Date while keeping theme and language as exact values @test
@generates
/**
* Generates a user profile with the given name and role.
* Includes both static fields (name, role, email) and dynamic fields
* (createdAt, userId, sessionToken) that change on each invocation.
*
* @param {string} name - The user's full name
* @param {string} role - The user's role (e.g., 'admin', 'user')
* @returns {Object} A user profile object with the following structure:
* - name: string (provided value)
* - role: string (provided value)
* - email: string (derived from name)
* - createdAt: Date (current timestamp)
* - userId: string (randomly generated UUID)
* - sessionToken: string (randomly generated token)
*/
function generateUserProfile(name, role) {
// IMPLEMENTATION HERE
}
/**
* Generates a user profile with nested address and preferences.
* Address includes a geocode with random coordinates.
* Preferences include a lastModified timestamp.
*
* @param {string} name - The user's full name
* @param {string} city - The city name
* @param {string} country - The country name
* @returns {Object} A user profile with nested objects:
* - name: string
* - email: string (derived from name)
* - address: Object with city, country, and geocode (lat/lng)
* - preferences: Object with theme, language, and lastModified
*/
function generateProfileWithAddress(name, city, country) {
// IMPLEMENTATION HERE
}
module.exports = {
generateUserProfile,
generateProfileWithAddress,
};Provides the testing framework with snapshot testing capabilities.
Install with Tessl CLI
npx tessl i tessl/npm-jest-eachdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10