Skip to content
On this page

Getting started

Earl is a ergonomic, modern and type-safe assertion library written in TypeScript. You might be familiar with similar libraries like: chai or assert. Earl should be used with a test runner like mocha, ava or tape.

To install earl run:

sh
npm install --save-dev earljs

With earl your assertions looks like this:

typescript
import { expect } from 'earljs'

expect(response).toEqual({
  body: { trimmed: true, timestamp: expect.a(String) },
})

We call functions like toEqual validators (well because they validate stuff...) and functions like expect.a matchers, you guessed it, because they match values. Matchers can be used to match whole ranges of values and are very important piece of earl ecosystem.

You can read more about those concepts in Core Concepts chapter.

Earl's killer feature is type-safety meaning that assertions that will for sure fail result in compile-time error.

typescript
import { expect } from 'earljs'

const meaningOfLife = 42

// TS error: Argument of type 'String' is not assignable to parameter of type 'number'
expect(meaningOfLife).toEqual(expect.a(String))

Lets do a step by step guide and write a first test case using mocha and earl!

Released under the MIT License.