chai

Chai assertion library for JavaScript. Use for JS assertions.

7 stars

Best use case

chai is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Chai assertion library for JavaScript. Use for JS assertions.

Teams using chai should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/chai/SKILL.md --create-dirs "https://raw.githubusercontent.com/G1Joshi/Agent-Skills/main/skills/testing/chai/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/chai/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How chai Compares

Feature / AgentchaiStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Chai assertion library for JavaScript. Use for JS assertions.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Chai

Chai is an assertion library. It pairs naturally with Mocha. It supports TDD (`assert`) and BDD (`expect`, `should`) styles.

## When to Use

- **With Mocha**: The default pair.
- **Expressive Tests**: You want tests to read like English ("expect foo to be a string").

## Quick Start

```javascript
import { expect } from "chai";

const foo = "bar";
const beverages = { tea: ["chai", "matcha", "oolong"] };

expect(foo).to.be.a("string");
expect(foo).to.equal("bar");
expect(foo).to.have.lengthOf(3);
expect(beverages).to.have.property("tea").with.lengthOf(3);
```

## Core Concepts

### Styles

- **Assert**: Classic. `assert.equal(foo, 'bar')`.
- **Expect**: BDD. Chainable. `expect(foo).to.be.equal('bar')`.
- **Should**: BDD. Extends Object prototype. `foo.should.be.equal('bar')`. (Less common now due to side effects).

### Plugins

Chai has a rich ecosystem.

- `chai-http`: For API testing.
- `chai-as-promised`: For asserting promises (`return expect(promise).to.eventually.equal(2)`).

## Best Practices (2025)

**Do**:

- **Stick to one style**: Usually **Expect**. It's clean and doesn't modify prototypes.
- **Use Descriptive Chains**: `to.be.true` reads better than `to.equal(true)`.

**Don't**:

- **Don't mix Assert and Expect**: Confuses the reader.

## References

- [Chai Documentation](https://www.chaijs.com/)