![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Ergonomic, modern and type-safe assertion library
Brings good parts of Jest back to good ol' Mocha
npm install --save-dev earljs
import { expect } from 'earljs'
const response = await apiCall()
expect(response).toEqual({ body: { trimmed: true, timestamp: expect.any() } })
I used to love mocha + chai combo, but as time flew, I felt it's limiting. Other projects like Jest shown that there is
room for innovation in this space. With last version published 2 years ago, Chai
seems abandoned. Furthermore, as
TypeScript becomes more and more popular, it became evident that some things about writing assertions could be improved.
Earl is an effort to bring a little bit of innovation in the space of assertion libraries.
I really enjoy some of the Jest's features — that's what inspired this library in the first place. However, I really hate others. Simply put, Jest feels too magical and full of bugs for my taste. Lots of its complexity comes from the features that I don't even care about like modules mocking or test parallelization. On the other hand, I always enjoyed simplicity and confidence that Mocha provides.
Matchers can be values like expect.anything()
and can be combined with toEqual
. Allowing, for example to easily
assert not fully deterministic objects. Unlike chai-subset
using this asserts much more info about actual object
shape.
expect({
abc: 'abc',
timestamp: '05/02/2020 @ 8:09am (UTC)',
}).toEqual({ abc: 'abc', timestamp: expect.anyString() })
expect(5).toEqual('abc') // errors during compile time
// matchers are always functions, not properties which goes well with `no-unused-expressions` eslint rule
Automatically fix expected (if omitted) values to match actual. Option to force fix existing values. Works with different matchers.
Implementation requires stack traces with correct sourcemaps - available in 99% environments. This feature is inspired by Jest's inline snapshots.
expect(serverResponse).toEqual()
// becomes after first run
expect(serverResponse).toEqual({ users: [{ name: 'Kris Kaczor' }] })
Yes you! This document presents current best thinking behind this project. Help us to guide it's future development! If you like what you see give us a 🌟. Don't hesitate to create issue in this project or reach out me directly on twitter (@krzkaczor).
toEqual
- performs deep equality check, ensures type equality works with asymmetric matchersanything
- matches anythinga(class)
- matches any instance of a class. Works as expected with primitives like String, Number etc. Use
a(Object)
to match any object (won't match null)stringContaining(substring)
- matches any string containing given substringI would call the current state a Minimal MVP ;) All of the features mentioned above work but are very limited. There are only 2 matchers currently, autofix relies on raw text manipulation.
All of this will be improved after initial round of feedback.
Re-implements most common chai
matchers and makes them part of the core.
TypeSafe Chai style plugins with additional matchers etc. Matchers can (and should!) implement support for autofix.
Thanks goes to these wonderful people (emoji key):
Kris Kaczor 💻 📖 🤔 | Piotr Szlachciak 🤔 🎨 | Artur Kozak 🤔 |
Contributions of any kind welcome!
Earl logo by @sz-piotr
Krzysztof Kaczor MIT
FAQs
Ergonomic, modern and type-safe assertion library
The npm package earljs receives a total of 387 weekly downloads. As such, earljs popularity was classified as not popular.
We found that earljs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.