☕ Ergonomic, modern and type-safe assertion library for TypeScript
MIT License
Bot releases are visible (Hide)
Published by sz-piotr 6 months ago
Published by github-actions[bot] over 1 year ago
Published by github-actions[bot] over 1 year ago
54b295f: Earl 1.0.0
This is the first stable release of Earl. It is an almost complete rewrite of the original Earl. The new version is much simpler, more powerful and easier to use.
Changes from the previous version
The package name has changed from earljs
to earl
. The old package name will be deprecated on npm.
Website updates
The website domain name has changed from https://earljs.dev
to https://earl.fun
.
The old domain will keep redirecting to the new one for a while.
The documentation has been updated to include new guides, more examples.
The documentation engine changed from Docusaurus to Vitepress.
Snapshot testing no longer relies on jest-snapshot
.
We developed a custom implementation which is much simpler and easier to maintain.
Snapshots are now saved alongside test files inside .snapshot
files.
The toMatchSnapshot
validator now requires a test context to be passed to it. This is done by passing this
in mocha and ctx
in uvu.
Test runner integration namely earljs/mocha
and earljs/uvu
are no longer needed and have been removed.
Extending Earl with custom matchers and validators is now much easier. Instead of a special plugin system, custom matchers and validators are defined in the same way as the built in ones.
Adding validators is now done using registerValidator
and declaring module overrides to make types work.
Adding matchers is now done using registerMatcher
and declaring module overrides to make types work.
The ability to add custom equality rules was removed and there are no plans to bring it back in the future.
A special export earljs/internal
is no longer needed and has been removed.
Validator API changes
The expect()
function now only takes a single argument, which is the value to be tested. No custom options can be passed to it.
toBeAContainerWith
has been replaced by toInclude
.
toBeAnArrayOfLength
has been replaced by toHaveLength
.
toBeAnArrayWith
has been replaced by toInclude
.
toBeAnObjectWith
has been removed. We are planning to add a new toHaveSubset
validator in the near future.
toBeDefined
was removed. It was unintuitive that it checked both null
and undefined
. Instead you should now call expect(value).not.toBeNullish()
.
toBeExhausted
has replaced by toHaveBeenExhausted
.
toBeGreaterThan
now works with numbers and bigints.
toBeGreaterThanOrEqualTo
has been replaced by toBeGreaterThanOrEqual
and now works with numbers and bigints.
toBeLessThan
now works with numbers and bigints.
toBeLessThanOrEqualTo
has been replaced by toBeLessThanOrEqual
and now works with numbers and bigints.
toBeRejected
doesn't take arguments anymore. Instead you should use toBeRejectedWith
to check the error.
toEqual
no longer has type checking problems with recursive types.
toHaveBeenCalledExactlyWith
has been removed. It was a very ugly API. It has been replaced by a suite of new mock validators.
toMatchSnapshot
now requires a test context to be passed to it. This is done by passing this
in mocha and ctx
in uvu.
toReferentiallyEqual
has been replaced by toExactlyEqual
.
toThrow
now always fails if the function returns a promise.
Matcher API changes
All matchers now return never
instead of trying to imitate the type of the value they are matching. This behavior is going to stay until TypeScript introduces a better way to do this.
arrayOfLength
has been replaced by length
.
arrayWith
has been replaced by includes
.
containerWith
has been replaced by includes
.
defined
now checks for only undefined
. Previously it checked for both null
and undefined
. Instead you should now call notNullish
.
numberCloseTo
has been replaced by closeTo
. The second parameter is now just the delta and not an object with the delta
property.
numberGreaterThan
has been replaced by greaterThan
and now works with numbers and bigints.
numberGreaterThanOrEqualTo
has been replaced by greaterThanOrEqual
and now works with numbers and bigints.
numberLessThan
has been replaced by lessThan
and now works with numbers and bigints.
numberLessThanOrEqualTo
has been replaced by lessThanOrEqual
and now works with numbers and bigints.
objectWith
has been replaced by subset
.
stringMatching
has been replaced by includes
and regex
.
Mock API changes
Fix types for mocks. Previously, the types for .executes
and .executesOnce
were incorrect.
Rename Mock
to MockFunction
.
Rename MockOf
to MockFunctionOf
.
Calling configuration functions that change the default mock behavior no longer resets the mock. An explicit reset
function has been added for that purpose.
New features
New validators
toBeAnInteger
.
toBeASafeInteger
.
toBeBetween
.
toBeCloseTo
.
toBeEmpty
.
toEqualUnsorted
.
toHaveBeenCalled
.
toHaveBeenCalledTimes
.
toHaveBeenLastCalledWith
.
toHaveBeenNthCalledWith
.
toHaveBeenOnlyCalledWith
.
toMatchRegex
.
toMatchSchema
.
toSatisfy
.
New matchers
between
.
closeTo
.
empty
.
integer
.
notEmpty
.
notNullish
.
property
.
regex
.
safeInteger
.
satisfies
.
schema
.
subset
.
New mock capabilities
mockObject
that can be used to mock objects.Published by github-actions[bot] over 2 years ago
1887ac2: Snapshot tests in uvu
are now supported with earljs/uvu
.
To use Earl with uvu
, require earljs/uvu
in your test command:
# using the uvu cli
$ uvu -r earljs/uvu tests
# using node directly
$ node -r earljs/uvu tests/example.test.js
Published by github-actions[bot] over 2 years ago
Published by github-actions[bot] over 2 years ago
Published by github-actions[bot] almost 3 years ago
toBeTruthy
, toBeFalsy
, toBeDefined
, toBeNullish
toBeAnArrayWith
and toBeAContainerWith
handle repeated items as expectedtoEqual
types via pluginsPublished by github-actions[bot] almost 3 years ago
Published by github-actions[bot] almost 3 years ago
Published by github-actions[bot] almost 4 years ago
rejectsWithOnce
and ensure that no unhandled rejection error can be thrown.objectWith
work with all kinds of objects, not only with plain objects. This is a breaking change.Published by github-actions[bot] almost 4 years ago
c4c75c8: Control.assert
type changed from never to void.
ceb7d92: Added new validators:
toBeA
toBeAContainerWith
toBeAnArrayOfLength
toBeAnArrayWith
toBeAnObjectWith
Added new matchers:
expect.arrayOfLength
3335eca: Stop exporting loadMatchers
from the main entry point.
d99dcee: Add new number validators:
toBeGreaterThanOrEqualTo(number)
toBeLessThan(number)
toBeLessThanOrEqualTo(number)
toBeExhausted(number)
3335eca: Replace Partial<PluginConfig>
instances with the equivalent PluginConfig
.
c4c75c8: Added Control.fail
.
3335eca: Improve doc comments and function parameter names for the public library exports.
Published by github-actions[bot] almost 4 years ago
toReferentiallyEqual
validator performing referential equalityErrorMatcher
description in error stringscontrol.assert
return never
not void
.Published by github-actions[bot] almost 4 years ago
Published by github-actions[bot] almost 4 years ago
toMatchSnapshot
validatorStringMatching
matcher that prevented it from matching strings with special charactersarrayWith
, objectWith
Improve containerWith
to work with multiple values