{"version":3,"file":"throw.cjs","sources":["../../../src/matchers/throw.js"],"sourcesContent":["import { getMatcherResult } from './utils.js';\nimport { isAsyncMatcherResult } from './asyncMatcherWrapper.js';\n\n/**\n * Extract error message from various error types\n */\nfunction extractErrorMessage(error) {\n  if (typeof error === 'string') {\n    return error;\n  }\n  if (error && error.message) {\n    return error.message;\n  }\n  if (error) {\n    return String(error);\n  }\n  return '';\n}\n\n/**\n * Check if an error matches the expected criteria\n */\nfunction matchesExpectedError(error, expected) {\n  if (!expected) return true;\n  \n  const errorMessage = extractErrorMessage(error);\n  \n  if (typeof expected === 'string') {\n    return errorMessage.includes(expected);\n  }\n  if (expected instanceof RegExp) {\n    return expected.test(errorMessage);\n  }\n  if (typeof expected === 'function') {\n    return error instanceof expected;\n  }\n  \n  return false;\n}\n\n/**\n * Handle async operations (promises, async matchers)\n */\nfunction handleAsyncOperation(asyncOperation, received, expected) {\n  return asyncOperation.then(\n    () => getMatcherResult(false, 'toThrow', received, expected),\n    (err) => getMatcherResult(matchesExpectedError(err, expected), 'toThrow', received, expected)\n  );\n}\n\n/**\n * Get the async operation from different types of received values\n */\nfunction getAsyncOperation(received) {\n  // Handle promises\n  if (received && typeof received.then === 'function') {\n    return received;\n  }\n  \n  // Handle raw async matcher results\n  if (isAsyncMatcherResult(received)) {\n    return received.execute();\n  }\n  \n  // Handle enhanced async matcher result wrappers\n  if (received && received.asyncMatcherResult && isAsyncMatcherResult(received.asyncMatcherResult)) {\n    return received.asyncMatcherResult.execute();\n  }\n  \n  return null;\n}\n\nexport function toThrow(received, expected) {\n  // Handle async operations\n  const asyncOperation = getAsyncOperation(received);\n  if (asyncOperation) {\n    return handleAsyncOperation(asyncOperation, received, expected);\n  }\n  \n  // Handle synchronous functions\n  let threw = false;\n  let error;\n  \n  try {\n    if (typeof received === 'function') {\n      received();\n    }\n  } catch (err) {\n    threw = true;\n    error = err;\n  }\n  \n  if (!threw) {\n    return getMatcherResult(false, 'toThrow', received, expected);\n  }\n  \n  return getMatcherResult(matchesExpectedError(error, expected), 'toThrow', received, expected);\n} \n"],"names":["getMatcherResult","isAsyncMatcherResult"],"mappings":";;;;;AAGA;AACA;AACA;AACA,SAAS,mBAAmB,CAAC,KAAK,EAAE;AACpC,EAAE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AACjC,IAAI,OAAO,KAAK;AAChB,EAAE;AACF,EAAE,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,EAAE;AAC9B,IAAI,OAAO,KAAK,CAAC,OAAO;AACxB,EAAE;AACF,EAAE,IAAI,KAAK,EAAE;AACb,IAAI,OAAO,MAAM,CAAC,KAAK,CAAC;AACxB,EAAE;AACF,EAAE,OAAO,EAAE;AACX;;AAEA;AACA;AACA;AACA,SAAS,oBAAoB,CAAC,KAAK,EAAE,QAAQ,EAAE;AAC/C,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,IAAI;AAC5B;AACA,EAAE,MAAM,YAAY,GAAG,mBAAmB,CAAC,KAAK,CAAC;AACjD;AACA,EAAE,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;AACpC,IAAI,OAAO,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC;AAC1C,EAAE;AACF,EAAE,IAAI,QAAQ,YAAY,MAAM,EAAE;AAClC,IAAI,OAAO,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC;AACtC,EAAE;AACF,EAAE,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;AACtC,IAAI,OAAO,KAAK,YAAY,QAAQ;AACpC,EAAE;AACF;AACA,EAAE,OAAO,KAAK;AACd;;AAEA;AACA;AACA;AACA,SAAS,oBAAoB,CAAC,cAAc,EAAE,QAAQ,EAAE,QAAQ,EAAE;AAClE,EAAE,OAAO,cAAc,CAAC,IAAI;AAC5B,IAAI,MAAMA,sBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC;AAChE,IAAI,CAAC,GAAG,KAAKA,sBAAgB,CAAC,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