> ## Documentation Index
> Fetch the complete documentation index at: https://docs.commonality.co/llms.txt
> Use this file to discover all available pages before exploring further.

# defineTestCheck

export const CheckContext = ({defaultPath, defaultRelativePath, children}) => <ParamField path="context" type="CheckContext">
    An object containing metadata about the package the check is being run against.

    <Expandable title="check-context-properties">
      {children ?? <>
          <ParamField path="tags" type="string[]" default={[]}>
            The tags that are applied via package configuation to the package being checked
          </ParamField>
          <ParamField path="codeowners" type="string[]" default={[]}>
            The codeowners for the package currently being checked
          </ParamField>
        </>}

      <ParamField path="package" type="PackagePaths">
        An object containing paths to the root directory of the package being checked.
        <Expandable title="package-properties">
          <ParamField path="path" type="string">
            A fully qualified path to the package directory
          </ParamField>
          <ParamField path="relativePath" type="string">
            A relative path to the package directory relative to the root of the project
          </ParamField>
        </Expandable>
      </ParamField>


      <ParamField path="rootPackage" type="PackagePaths">
        An object containing paths to the root directory of the current project.

        <Expandable title="package-properties">
          <ParamField path="path" type="string">
            A fully qualified path to the package directory
          </ParamField>
          <ParamField path="relativePath" type="string">
            A relative path to the package directory relative to the root of the project
          </ParamField>
        </Expandable>
      </ParamField>

      <ParamField path="allPackages" type="PackagePaths[]">
        An array of objects containing paths to every package directory in the current project.
        <Expandable title="package-properties">
          <ParamField path="path" type="string">
            A fully qualified path to the package directory
          </ParamField>
          <ParamField path="relativePath" type="string">
            A relative path to the package directory relative to the root of the project
          </ParamField>
        </Expandable>
      </ParamField>

    </Expandable>

  </ParamField>;

```ts theme={null}
(check: Check, context?: TestCheckContext) => Check
```

`defineTestCheck` wraps your checks and decorates these functions with sensible defaults for the `CheckContext` that is passed to your [message](/reference/check-object#message), [validate](/reference/check-object#validate) and [fix](/reference/check-object#fix) functions that you can override.
This cuts down on repetitive boilerplate when writing tests for your checks.

## Parameters

<ParamField path="check" type="Check" required>
  The [Check](/reference/check-object) object that you want to test
</ParamField>

<CheckContext defaultPath="./" defaultRelativePath="./">
  <ParamField path="tags" type="string[]" default={[]}>
    The tags that you want to test the check with
  </ParamField>

  <ParamField path="codeowners" type="string[]" default={[]}>
    The codeowners that you want to test the check with
  </ParamField>
</CheckContext>

## Returns

Returns the original check function, however the `validate`, `fix`, and `message` functions
will be passed the defaults in `TestCheckContext` rather than requiring that all properties `CheckContext` are explicitly passed when testing check methods.

## Example

```ts theme={null}
// Without defineTestCheck
test('validate - returns true when valid', () => {
  mockFs({
    'package.json': JSON.stringify({
      name: 'foo',
      description: 'bar',
    }),
  });

  const check = myCheck();
  const result = myCheck.validate({
    package: {
      path: './',
      relativePath: './',
    },

    allPackages: [
      {
        path: './',
        relativePath: './',
      },
    ],
    codeowners: [],
    tags: [],
  });

  expect(result).toEqual(true);
});

// With defineTestCheck
test('validate - returns true when valid', () => {
  mockFs({
    'package.json': JSON.stringify({
      name: 'foo',
      description: 'bar',
    }),
  });

  const check = defineTestCheck(myCheck());
  const result = myCheck.validate();

  expect(result).toEqual(true);
});
```
