-
bc6c0a9: Make string snapshots preserve new lines. This makes snapshots of long strings, such as source code easy to review.
This change is backwards-compatible, meaning that previously recorded snapshots remain valid. However, once you update snapshots, the new style will be used, and snapshots may be updated even if the underlying object stays the same.
- ed0c287: Add support for node:test
- A maintenance release. The code now uses biome instead of eslint + prettier. It also uses the newest version of TypeScript and features an updated tsconfig.json. End users shouldn't notice any changes.
- 46f000c: Add .clear to mocks which clears the calls array. Fixes .reset not clearing the calls.
- e5ce81a: Add mockObject.reset which resets all functions on MockObject
- ce60bac: Improve performance by making some error messages lazy
- 3a60d1f: Add toHaveSubset validator
- 2886d70: Fix esm exports
-
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
earljstoearl. The old package name will be deprecated on npm.- The new release includes both CommonJS and ESM builds.
-
Website updates
-
The website domain name has changed from
https://earljs.devtohttps://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
.snapshotfiles. -
The
toMatchSnapshotvalidator now requires a test context to be passed to it. This is done by passingthisin mocha andctxin uvu. -
Test runner integration namely
earljs/mochaandearljs/uvuare 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
registerValidatorand declaring module overrides to make types work. -
Adding matchers is now done using
registerMatcherand 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/internalis 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. -
toBeAContainerWithhas been replaced bytoInclude. -
toBeAnArrayOfLengthhas been replaced bytoHaveLength. -
toBeAnArrayWithhas been replaced bytoInclude. -
toBeAnObjectWithhas been removed. We are planning to add a newtoHaveSubsetvalidator in the near future. -
toBeDefinedwas removed. It was unintuitive that it checked bothnullandundefined. Instead you should now callexpect(value).not.toBeNullish(). -
toBeExhaustedhas replaced bytoHaveBeenExhausted. -
toBeGreaterThannow works with numbers and bigints. -
toBeGreaterThanOrEqualTohas been replaced bytoBeGreaterThanOrEqualand now works with numbers and bigints. -
toBeLessThannow works with numbers and bigints. -
toBeLessThanOrEqualTohas been replaced bytoBeLessThanOrEqualand now works with numbers and bigints. -
toBeRejecteddoesn't take arguments anymore. Instead you should usetoBeRejectedWithto check the error. -
toEqualno longer has type checking problems with recursive types. -
toHaveBeenCalledExactlyWithhas been removed. It was a very ugly API. It has been replaced by a suite of new mock validators. -
toMatchSnapshotnow requires a test context to be passed to it. This is done by passingthisin mocha andctxin uvu. -
toReferentiallyEqualhas been replaced bytoExactlyEqual. -
toThrownow always fails if the function returns a promise.
-
-
Matcher API changes
-
All matchers now return
neverinstead 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. -
arrayOfLengthhas been replaced bylength. -
arrayWithhas been replaced byincludes. -
containerWithhas been replaced byincludes. -
definednow checks for onlyundefined. Previously it checked for bothnullandundefined. Instead you should now callnotNullish. -
numberCloseTohas been replaced bycloseTo. The second parameter is now just the delta and not an object with thedeltaproperty. -
numberGreaterThanhas been replaced bygreaterThanand now works with numbers and bigints. -
numberGreaterThanOrEqualTohas been replaced bygreaterThanOrEqualand now works with numbers and bigints. -
numberLessThanhas been replaced bylessThanand now works with numbers and bigints. -
numberLessThanOrEqualTohas been replaced bylessThanOrEqualand now works with numbers and bigints. -
objectWithhas been replaced bysubset. -
stringMatchinghas been replaced byincludesandregex.
-
-
Mock API changes
-
Fix types for mocks. Previously, the types for
.executesand.executesOncewere incorrect. -
Rename
MocktoMockFunction. -
Rename
MockOftoMockFunctionOf. -
Calling configuration functions that change the default mock behavior no longer resets the mock. An explicit
resetfunction 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
- Added
mockObjectthat can be used to mock objects.
- Added
-
-
1887ac2: Snapshot tests in
uvuare now supported withearljs/uvu.To use Earl with
uvu, requireearljs/uvuin your test command:# using the uvu cli $ uvu -r earljs/uvu tests # using node directly $ node -r earljs/uvu tests/example.test.js
- fde9d67: Fixed "a" matcher for functions
- 7378e50: Earl formatting no longer crashes on object with constructor set to undefined.
- 7dca1a2: Assertion errors throw with clean (without internal entries) stack traces
- 3973df6: Redo equality algorithm, improve error diffs
- 489321e: Add new validators and matchers:
toBeTruthy,toBeFalsy,toBeDefined,toBeNullish - 05013cd: Make
toBeAnArrayWithandtoBeAContainerWithhandle repeated items as expected - 489321e: Allow to override
toEqualtypes via plugins
- afbd34b: Ensure that package is published with the readme. Readme updates.
- d69576f: Fix types for mockFn's default implementation
- 00cae63: Function mocks can now be typed as Mock.Of
- a0f7b98: Improve support for comparing recursive objects
- 3651e17: Earl no longer crashes in mocha --watch mode
- d02b7d6: process.env.UPDATE_SNAPSHOTS set to "1" is now treated the same as when set to "true"
- f37f7fa: Improve types for
rejectsWithOnceand ensure that no unhandled rejection error can be thrown. - f37f7fa: Make
objectWithwork with all kinds of objects, not only with plain objects. This is a breaking change.
-
c4c75c8:
Control.asserttype changed from never to void. -
ceb7d92: Added new validators:
toBeAtoBeAContainerWithtoBeAnArrayOfLengthtoBeAnArrayWithtoBeAnObjectWith
Added new matchers:
expect.arrayOfLength
-
3335eca: Stop exporting
loadMatchersfrom the main entry point. -
d99dcee: Add new number validators:
toBeGreaterThanOrEqualTo(number)toBeLessThan(number)toBeLessThanOrEqualTo(number)toBeExhausted(number)
-
3335eca: Replace
Partial<PluginConfig>instances with the equivalentPluginConfig. -
c4c75c8: Added
Control.fail. -
3335eca: Improve doc comments and function parameter names for the public library exports.
- 69c6af3: Add
toReferentiallyEqualvalidator performing referential equality - 3f2ebc2: Improve
ErrorMatcherdescription in error strings - 3f2ebc2: [Plugin devs] Make
control.assertreturnnevernotvoid.
- 1ef1ad2: Adds the getControl function which is intended to be used by plugins.
- 125c29b: Tweak
toHaveBeenCalledExactlyWithinput type to properly support arrays - 923847b: Made
expect.a(Array)return type beany[]notunknown[]which works well withtoEqual.
- 1eac490: Add
toMatchSnapshotvalidator
- 591dccc: Add readme to the final npm package
- 4964a16: Migrated to monorepo.
- 4964a16: Fix bug in
StringMatchingmatcher that prevented it from matching strings with special characters - 1e3951d: Added new matchers:
arrayWith,objectWithImprovecontainerWithto work with multiple values - 4964a16: Added experimental plugin API.
- 0f490bd: Tweak
toBeRejectedvalidator signature to be properly async (returnPromise<void>). This was a bug in typings not in behaviour.
- d2efbc6: Change compilation target to ES2015 to enable running on older node.js versions
- 42ed317: Added
containerWithmatcher, allowing to match a iterable containing given value