Skip to content

Latest commit

 

History

History
70 lines (54 loc) · 2.13 KB

File metadata and controls

70 lines (54 loc) · 2.13 KB
sidebar_position 4
title API Reference
description Complete API reference for Suites testing framework

API Reference

API reference for setting up and managing unit tests with Suites.

Core APIs

Quick Reference

Creating a Solitary Test

const { unit, unitRef } = await TestBed.solitary(UserService).compile();

Creating a Sociable Test

const { unit, unitRef } = await TestBed.sociable(UserService)
  .expose(UserApi)  // Keep UserApi real
  .compile();

Configuring Mocks

// Final configuration (immutable)
await TestBed.solitary(UserService)
  .mock(UserApi)
  .final({ getRandom: async () => ({ id: 1, name: 'John' }) })
  .compile();

// Flexible configuration
await TestBed.solitary(UserService)
  .mock(UserApi)
  .impl(stubFn => ({ getRandom: stubFn().mockResolvedValue({ id: 1 }) }))
  .compile();

Creating Standalone Mocks

import { mock, stub } from '@suites/unit';

// Mock a full class
const userRepo = mock<UserRepository>();
userRepo.findById.mockResolvedValue(testUser);

// Create a stub function
const stubFn = stub();
stubFn.mockReturnValue(42);

Quick Terminology

  • Mock: A complete replacement of a dependency class where each method has been replaced with a stub
  • Stub: An individual method replacement that provides predefined responses
  • Mocked<T>: The type representing a mocked dependency with stubbed methods