> ## 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

```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](https://docs.commonality.co/reference/check-object.md#message), [validate](https://docs.commonality.co/reference/check-object.md#validate) and [fix](https://docs.commonality.co/reference/check-object.md#fix) functions that you can override.
This cuts down on repetitive boilerplate when writing tests for your checks.

## Parameters

**check** `Check` *required*

The [Check](https://docs.commonality.co/reference/check-object.md) object that you want to test

**context** `CheckContext`

An object containing metadata about the package the check is being run against.

**check-context-properties**

**tags** `string[]`

The tags that you want to test the check with

**codeowners** `string[]`

The codeowners that you want to test the check with

**package** `PackagePaths`

An object containing paths to the root directory of the package being checked.

**package-properties**

**path** `string`

A fully qualified path to the package directory
**relativePath** `string`

A relative path to the package directory relative to the root of the project

**rootPackage** `PackagePaths`

An object containing paths to the root directory of the current project.

**package-properties**

**path** `string`

A fully qualified path to the package directory
**relativePath** `string`

A relative path to the package directory relative to the root of the project

**allPackages** `PackagePaths[]`

An array of objects containing paths to every package directory in the current project.

**package-properties**

**path** `string`

A fully qualified path to the package directory
**relativePath** `string`

A relative path to the package directory relative to the root of the project

## 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);
});
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.