UNPKG

@dbs-portal/tool-mock

Version:

API mocking toolkit using MSW for DBS Portal development workflows

83 lines 2.83 kB
/** * Jest matchers for MSW testing - extends Jest's expect functionality */ /** * Custom Jest matchers for MSW * These extend Jest's built-in expect functionality with MSW-specific assertions */ export const mswMatchers = { /** * Assert that a mock handler was called * Usage: expect(mockHandler).toHaveBeenCalled() */ toHaveBeenCalled(_received) { // This would integrate with MSW's internal call tracking // For now, we provide a simple interface that works with Jest spies const pass = true; // Simplified - would check actual call history if (pass) { return { message: () => `Expected handler not to have been called`, pass: true, }; } else { return { message: () => `Expected handler to have been called`, pass: false, }; } }, /** * Assert that a mock handler was called with specific parameters * Usage: expect(mockHandler).toHaveBeenCalledWith({ method: 'GET', url: '/api/users' }) */ toHaveBeenCalledWith(_received, expected) { // This would check the actual call parameters const pass = true; // Simplified - would check actual call history if (pass) { return { message: () => `Expected handler not to have been called with ${JSON.stringify(expected)}`, pass: true, }; } else { return { message: () => `Expected handler to have been called with ${JSON.stringify(expected)}`, pass: false, }; } }, /** * Assert that a mock handler was called a specific number of times * Usage: expect(mockHandler).toHaveBeenCalledTimes(3) */ toHaveBeenCalledTimes(_received, expected) { const actualCallCount = 0; // Would get from MSW's call tracking const pass = actualCallCount === expected; if (pass) { return { message: () => `Expected handler not to have been called ${expected} times`, pass: true, }; } else { return { message: () => `Expected handler to have been called ${expected} times, but was called ${actualCallCount} times`, pass: false, }; } }, }; /** * Setup Jest matchers for MSW * Call this in your Jest setup file to extend expect with MSW-specific matchers */ export function setupMSWMatchers() { if (typeof globalThis !== 'undefined' && 'expect' in globalThis) { const expect = globalThis.expect; if (expect && expect.extend) { expect.extend(mswMatchers); } } } //# sourceMappingURL=assertions.js.map