Automattic / Automattic/expect.js

AssertionError

Open
#133 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.1k
Forks
207
PR merge metrics
No merged PRs in 30d

Description

In mochajs/mocha#1635, we are considering adding support for suite continuation if a hook throws an `AssertionError`.

Because **expect.js** doesn't actually throw an `AssertionError` upon failure, this feature will simply not work with **expect.js**.

Would like to start a discussion about **expect.js** throwing `AssertionError`s, much like **Chai** or **should**. I imagine:
- in a server context, use `require('assert').AssertionError`
- in a client context, the assertion library must define a global `AssertionError`. Example:

``` js
var AssertionError = function(message, actual, expected) {
this.message = message;
this.actual = actual;
this.expected = expected;
this.showDiff = true;
};
// or whatever you need to do for old browser support
AssertionError.prototype = Object.create(Error.prototype);
AssertionError.prototype.name = 'AssertionError';
AssertionError.prototype.constructor = AssertionError;
```

Would this break backwards compatibility? Any user checks of `err instanceof Error` should still work.

Contributor guide

No contributing guide indexed for this repository

Research direction

Review the issue's proposed server and browser AssertionError approaches and inspect expect.js's current assertion-failure behavior in both contexts. Determine whether introducing AssertionError would preserve existing Error checks and define what compatibility tests would demonstrate as done.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.