# Maddox `.test` Callback Contract

The `.test(callback)` method is the final step in any Maddox scenario. It executes the test and calls your provided callback with the results.

## The Contract

The callback follows the standard Node.js error-first pattern. For formal type definitions, TypeScript users can refer to `node_modules/maddox/index.d.ts`.

```javascript
.test((err, response) => {
  // ... your assertions here ...
});
```

### Parameters

1.  **`err`** *(Error | undefined)*: 
    *   In most scenarios (like `FromPromiseScenario`), this contains the error if the entry point function rejected or threw.
    *   In `RemixScenario` / `FrameworkRouteScenario`, this is almost always `undefined` because errors are typically caught by React Router's `ErrorBoundary` or handled as fatal Maddox Runtime Errors.
2.  **`response`** *(Any)*:
    *   The result of the scenario execution.
    *   **`RemixScenario`**: Returns an array of invocation objects:
        ```javascript
        [
          { 
            mockName: "HomeRoute", 
            kind: "loader", 
            value: { data: "success" }, 
            error: undefined 
          },
          { 
            mockName: "SubmitAction", 
            kind: "action", 
            value: undefined, 
            error: new Error("Validation Failed") 
          }
        ]
        ```
    *   **`FromPromiseScenario`**: Returns the resolved value of the promise.
    *   **`HttpReqScenario`**: Usually passed `done` directly, but if a callback is provided, `response` is the result of the controller execution.

## Why did I get "Unchecked Error (4004)"?

This error occurs when the code inside your `.test((err, response) => { ... })` callback throws an error that isn't caught. 

Common causes:
*   An assertion failed (e.g., `Maddox.compare.equal(actual, expected)`).
*   You tried to access a property on `undefined` (e.g., `response[0].value` when `response` is empty).
*   A syntax error or logic error in your test code.

**Important**: You should always ensure your assertions are correct and handle potential `undefined` values in your response to avoid this error.
