Here is a very high level overview of the major releases. See the changelog for more details.
- Drop support for node.js < 10
This release includes backwards-incompatible changes. There's a migration guide to help you upgrade.
- Drop support for node.js < 6
- The main export is now a frozen
expectfunction. To add assertions and install plugins, you must now
clone()it first (#517)
- Include non-enumerable properties when comparing objects (#482)
to satisfynow compares functions by value. Functions in the spec that are to be executed must now be wrapped in
functiontype is now modelled as a subtype of
object. This means that all assertions defined for
object, such as
to have properties, also work for functions now (#448)
- Drop compatibility with pre-10.10.0 diff objects. This will mainly affect older plugins (#407)
- Remove support for
- Remove long-deprecated support for
this.subjectetc. in assertion handlers (#567)
- Assertions are now declared with explicit type requirements for
the arguments as part of the pattern. This is a breaking change
that removes support for the old
addAssertionsyntax where the subject type(s) were passed as the first argument. See addAssertion for more information.
to be >,
to be >=,
to be <, and
to be <=assertions have been removed as they clashed with the new type syntax. Please use the fully spelled-out variants:
to be greater than,
to be less than or equal to, etc.
[not] to begin with,
[not] to end with, and
[not] to containassertions now require strings as the needle(s). Previously they supported any type, which would then be stringified.
- Inside an assertion you can now access the
alternationsproperties etc. via the
expectpassed to the assertion. They can still be accessed via
thisas previously, but that is deprecated. (This change actually debuted in 9.12.0).
when passed as parameter(s) to,
when called with,
when decoded asassertions can now be used standalone, ie. without delegating the result to another assertion in the same
expectcall. In that case they will provide the result as the fulfillment value of the promise.
- Build all error messages lazily. This is an internal refactoring that makes it possible to generate very different output in the text, Ansi, and HTML modes using the magicpen raw feature. This change mostly affects plugins, and we have updated all the official plugins accordingly, so please upgrade those to the latest version when you upgrade to Unexpected 9.
- Made it possible to tweak the default error message when creating assertions. See addAssertion for more information.
- Expanded the
to have messageassertion defined for
Errorinstances to allow matching a serialization other than plain text:
to have ansi message,
to have html message.
to containassertion defined for strings: When the assertion fails, display a "diff" where partial matches are highlighted.
- All errors originating from assertions are now instances of
UnexpectedError, which can be manipulated before being serialized.
- Error messages and diffs are now built lazily, improving performance.
- Unexpected now detects created promises that were never returned and fails synchronously. This will uncover some extremely nasty bugs where the test suite succeeds when it should actually fail. This feature only works in Mocha and Jasmine.
- Deprecated error.output, please use error.getErrorMessage() instead.
- Deprecated error.label, please use error.getLabel() instead.
when decoded as,
when called with,
when passed as parameter to,
when passed as parameters to: Require the 4th argument to be a string specifying an assertion. Previously a function was also allowed, which turned out to be error prone. This also affects all plugins that use the internal function
Assertion.prototype.shiftto delegate to other assertions.
- Nested error mode: Don't repeat the subject when it takes up multiple lines and is identical to the parent subject.
- Added a new
bubbleThrougherror mode that will make the error bubble all the way to the top, mainly useful internally.
- Minor bugfixes and output tweaks.
- Support for
asynchronous assertions using promises.
All built-in assertions that delegate to other assertions (such as
to satisfy) have been rewritten to support this. The change is fully backwards compatible.
- Removed support for the
to be an array ofand
to be an array of (strings|numbers|...)assertions. There are better and more flexible alternatives.
- Renamed assertions so that the subject type isn't mentioned in the assertion name.
The old names are kept around as aliases for now. These assertions are affected:
to be an array whose items satisfy=>
to have items satisfying
to be an (object|hash|map) whose keys satisfy=>
to have keys satisfying
to be an (object|hash|map) whose values satisfy=>
to have values satisfyingAlso, these 3 assertions no longer pass for empty collections.
when passed as parameter to constructorand
when passed as parameter to async"adverbial" assertions.
when decoded as"adverbial" assertion for
to have messageassertion defined for
- A lot of output improvements and minor tweaks.
- New documentation and corresponding site.
Object.is/the SameValue algorithm when checking equality of primitive values (the
- Tweaked the output of numerous assertions.
to be emptyand
to have lengthto only work with strings and array-like objects.
- Renamed the
- Changed style names and added theming support (mostly internal).
- Removed grammatically incorrect assertions.
- Add custom diffs for many assertions.
- Removed the word "minimalistic" from the sales pitch in the documention :)
- Added type system for assertion subjects.
- Use magicpen for all generating all output. No longer rely on the tests runner to render diffs.
- Hand an expect function to custom assertions.
- Added the ability for an assertion to control how the error message of nested expect calls are formatted.
to have propertiesgets introduced.
- Tightened up equality semantics.
- First release that's not 0.x!