{"version":3,"file":"spyValidation.cjs","sources":["../../../src/matchers/spyValidation.js"],"sourcesContent":["import { isSpy, isMockFunction } from './spy.js';\n\n/**\n * Validates if a value is a spy or mock function\n * @param {*} value - The value to validate\n * @returns {boolean} - True if the value is a valid spy or mock function\n */\nexport function isValidSpyOrMock(value) {\n  return isSpy(value) || isMockFunction(value);\n}\n\n/**\n * Validates spy/mock function and throws descriptive error if invalid\n * @param {*} value - The value to validate\n * @param {string} matcherName - The name of the matcher for error reporting\n * @throws {Error} - If the value is not a valid spy or mock function\n */\nexport function validateSpyOrMock(value, matcherName) {\n  if (!isValidSpyOrMock(value)) {\n    const error = new Error(\n      `${matcherName} matcher can only be used on spy or mock functions. ` +\n      `Received: ${typeof value}${value ? ` (${value.constructor.name})` : ''}`\n    );\n    error.actual = value;\n    error.matcherName = matcherName;\n    throw error;\n  }\n}\n\n/**\n * Validates that both functions are valid spy/mock functions\n * @param {*} fn1 - The first function to validate\n * @param {*} fn2 - The second function to validate\n * @param {string} matcherName - The name of the matcher for error reporting\n * @throws {Error} - If either function is not a valid spy or mock function\n */\nexport function validateTwoSpiesOrMocks(fn1, fn2, matcherName) {\n  if (!isValidSpyOrMock(fn1)) {\n    const error = new Error(\n      `${matcherName} matcher can only be used on spy or mock functions. ` +\n      `First argument received: ${typeof fn1}${fn1 ? ` (${fn1.constructor.name})` : ''}`\n    );\n    error.actual = fn1;\n    error.matcherName = matcherName;\n    throw error;\n  }\n  \n  if (!isValidSpyOrMock(fn2)) {\n    const error = new Error(\n      `${matcherName} matcher can only be used on spy or mock functions. ` +\n      `Second argument received: ${typeof fn2}${fn2 ? ` (${fn2.constructor.name})` : ''}`\n    );\n    error.actual = fn2;\n    error.matcherName = matcherName;\n    throw error;\n  }\n}\n\n/**\n * Validates that a spy/mock function has been called at least once\n * @param {Function} fn - The function to validate\n * @param {string} matcherName - The name of the matcher for error reporting\n * @throws {Error} - If the function has not been called\n */\nexport function validateFunctionHasBeenCalled(fn, matcherName) {\n  validateSpyOrMock(fn, matcherName);\n  \n  const callCount = getCallCount(fn);\n  if (callCount === 0) {\n    const error = new Error(\n      `${matcherName} matcher requires the function to have been called at least once. ` +\n      `Received: function with ${callCount} calls`\n    );\n    error.actual = fn;\n    error.matcherName = matcherName;\n    throw error;\n  }\n}\n\n/**\n * Helper function to get call count (works with both spy and mock functions)\n * @param {Function} fn - The function to get call count for\n * @returns {number} - The number of times the function has been called\n */\nfunction getCallCount(fn) {\n  if (isSpy(fn)) {\n    return fn.callCount;\n  } else if (isMockFunction(fn)) {\n    return fn.mock.calls.length;\n  }\n  return 0;\n}\n"],"names":["isSpy","isMockFunction"],"mappings":";;;;AAEA;AACA;AACA;AACA;AACA;AACO,SAAS,gBAAgB,CAAC,KAAK,EAAE;AACxC,EAAE,OAAOA,SAAK,CAAC,KAAK,CAAC,IAAIC,kBAAc,CAAC,KAAK,CAAC;AAC9C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,iBAAiB,CAAC,KAAK,EAAE,WAAW,EAAE;AACtD,EAAE,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE;AAChC,IAAI,MAAM,KAAK,GAAG,IAAI,KAAK;AAC3B,MAAM,CAAC,EAAE,WAAW,CAAC,oDAAoD,CAAC;AAC1E,MAAM,CAAC,UAAU,EAAE,OAAO,KAAK,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;AAC9E,KAAK;AACL,IAAI,KAAK,CAAC,MAAM,GAAG,KAAK;AACxB,IAAI,KAAK,CAAC,WAAW,GAAG,WAAW;AACnC,IAAI,MAAM,KAAK;AACf,EAAE;AACF;;;;;"}