UNPKG

@dbs-portal/core-api

Version:

HTTP client and API utilities for DBS Portal

43 lines 1.38 kB
/** * Test utils for MSW integration tests * This file contains utilities to help with MSW testing in Node.js environment */ import { http } from 'msw'; /** * Base URL for API requests in tests */ export const TEST_BASE_URL = 'http://localhost:3000'; /** * Helper to ensure proper URL format for MSW handlers * This is particularly important for MSW v2 which needs exact URL matching */ export function createTestUrl(path) { // If already a full URL, return as is if (path.startsWith('http://') || path.startsWith('https://')) { return path; } // Ensure path starts with a slash const normalizedPath = path.startsWith('/') ? path : `/${path}`; // Return the full URL return `${TEST_BASE_URL}${normalizedPath}`; } /** * Creates proper request headers for MSW testing in Node environment * This helps with IPv4/IPv6 localhost resolution issues */ export function createTestHeaders() { return { // Helps with localhost resolution in MSW 'X-MSW-Bypass': 'no', // Prevent automatic redirects that might break tests 'X-Test-Header': 'msw-test' }; } /** * Create a GET handler with proper URL for tests */ export function createTestHandler(method, path, resolver) { const fullUrl = createTestUrl(path); return http[method](fullUrl, resolver); } //# sourceMappingURL=msw-test-helpers.js.map