Testing GuidesOverview

Testing Guides

MockMaster integrates seamlessly with popular testing frameworks.


Supported Frameworks

Vitest

Fast, modern unit and integration testing for Vite projects.

Features:

  • Native ESM support
  • Fast execution
  • Compatible API with Jest
  • Built-in TypeScript support
npm install -D vitest

Jest

Popular JavaScript testing framework with comprehensive features.

Features:

  • Snapshot testing
  • Mocking utilities
  • Code coverage
  • Large ecosystem
npm install -D jest

Playwright

End-to-end testing for modern web applications.

Features:

  • Cross-browser testing
  • Auto-wait for elements
  • Network interception
  • Visual regression testing
npm install -D @playwright/test

Common Patterns

Load Scenario in Tests

import { readScenario } from '@mockmaster/cli'
import { createReplayHandler } from '@mockmaster/msw-adapter'
 
const scenario = await readScenario('./scenarios', 'user-api')
const handler = createReplayHandler(scenario)
 
const response = handler({ method: 'GET', path: '/users' })

Setup in beforeEach

describe('API Tests', () => {
  let handler: ReturnType<typeof createReplayHandler>
 
  beforeEach(async () => {
    const scenario = await readScenario('./scenarios', 'user-api')
    handler = createReplayHandler(scenario)
  })
 
  it('fetches users', () => {
    const response = handler({ method: 'GET', path: '/users' })
    expect(response.status).toBe(200)
  })
})

Framework-Specific Guides


Next Steps

Choose your testing framework and follow the detailed guide:

  1. Vitest - For modern Vite-based projects
  2. Jest - For traditional JavaScript projects
  3. Playwright - For end-to-end testing