@magic/test

Error Codes

@magic/test uses error codes to help with debugging and programmatic error handling. You can import these constants from `@magic/test`:

import { ERRORS, createError } from '@magic/test'

Available Error Codes

| Code | Description |

| ---- | ----------- |

| ERRORS.E_EMPTY_SUITE | Test suite is not exporting any tests |

| ERRORS.E_RUN_SUITE_UNKNOWN | Unknown error occurred while running a suite |

| ERRORS.E_TEST_NO_FN | Test object is missing the `fn` property |

| ERRORS.E_TEST_EXPECT | Test expectation failed |

| ERRORS.E_TEST_BEFORE | Before hook failed |

| ERRORS.E_TEST_AFTER | After hook failed |

| ERRORS.E_TEST_FN | Test function threw an error |

| ERRORS.E_NO_TESTS | No test suites found |

| ERRORS.E_IMPORT | Failed to import a test file |

| ERRORS.E_MAGIC_TEST | General test execution error |

createError

Create custom errors with specific codes and messages:

import { createError, ERRORS } from '@magic/test'export default [  {    fn: () => createError(ERRORS.E_TEST_NO_FN, 'Missing fn property'),    expect: e => e.code === 'E_TEST_NO_FN' && e.message === 'Missing fn property',    info: 'createError creates errors with code and message',  },]

Usage Example

try {  // run tests} catch (e) {  if (e.code === ERRORS.E_TEST_NO_FN) {    console.error('Test is missing fn property:', e.message)  } else if (e.code === ERRORS.E_TEST_FN) {    console.error('Test function threw an error:', e.message)  } else if (e.code === ERRORS.E_IMPORT) {    console.error('Failed to import test file:', e.message)  }}

Error Object Properties

  • code - The error code string (e.g., "E_TEST_NO_FN")
  • message - Human-readable error message
  • stack - Stack trace for debugging