> For the complete documentation index, see [llms.txt](https://ddzy.gitbook.io/ts-utility-plugins-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ddzy.gitbook.io/ts-utility-plugins-docs/utility/utility-others/invariant.md).

# invariant

### 说明

&#x20;自定义的异常处理机制(`用于本仓库使用`)

### 源码

<https://github.com/ddzy/ts-utility-plugins/tree/master/src/ddzy/utility/others/invariant>

### 用法

{% code title="invariant.test.ts" %}

```typescript
import { invariant } from "../../utility/others/invariant";

describe('invariant', () => {

  // ! Test successed
  // test('invariant should throw error when the condition to be true', () => {
  //   expect(utilityOthers.invariant(true, 'test error')).toThrowErrorMatchingSnapshot();
  // });

  test('invariant should not do anything when the condition to be false', () => {
    expect(invariant(false, 'test error')).toBeFalsy();
  });
});
```

{% endcode %}
