Skip to content

Commit 0de23a6

Browse files
committed
docs: update proposal to reflect polymorphic expectFailure API
1 parent abb5912 commit 0de23a6

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

proposals/expect-failure-enhancements.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,28 @@ test('fails with a specific reason', {
2121
- **Validation**: None. It accepts *any* error.
2222
- **Output**: The reporter displays the string (e.g., `# EXPECTED FAILURE Bug #123...`).
2323

24-
### 2. RegExp: Error Matcher (via Object)
25-
Use the object form with the `with` property.
24+
### 2. Validation (RegExp, Class, Function, Object)
25+
If the value is a **RegExp**, **Class**, **Function**, or an **Object** (without a `with` property), it is treated as an error matcher.
2626

2727
```js
28-
test('fails with matching error', {
29-
expectFailure: { with: /expected error message/ }
28+
test('fails with matching regex', {
29+
expectFailure: /expected error message/
3030
}, () => {
31-
throw new Error('this is the expected error message');
31+
throw new Error('expected error message');
32+
});
33+
34+
test('fails with matching class', {
35+
expectFailure: TypeError
36+
}, () => {
37+
throw new TypeError('wrong type');
3238
});
3339
```
40+
- **Behavior**: The test passes **only if** the thrown error matches the criteria.
41+
- **Validation**: Uses `assert.throws` logic internally.
42+
- **Output**: Reporter shows generated message (e.g. `# EXPECTED FAILURE matching /regex/`).
3443

35-
### 3. Object: Reason & Validation
36-
When an **Object** is provided, it allows specifying both a failure reason and validation logic simultaneously.
44+
### 3. Explicit Configuration Object
45+
To provide **both** a reason and validation, use an object with `message` and `with` properties.
3746

3847
```js
3948
test('fails with reason and specific error', {
@@ -46,15 +55,14 @@ test('fails with reason and specific error', {
4655
});
4756
```
4857
- **Properties**:
49-
- `message` (String): The failure reason/label (displayed in reporter).
50-
- `with` (RegExp | Object | Function | Class): Validation logic. This is passed directly to `assert.throws` validation argument, supporting all its capabilities.
51-
- **Behavior**: The test passes **only if** the error matches the `with` criteria.
52-
- **Output**: The reporter displays the `message`.
58+
- `message` (String): The failure reason/label.
59+
- `with` (Any): Validation logic passed to `assert.throws`.
5360

5461
## Ambiguity Resolution
55-
Potential ambiguity is resolved by strict type separation:
62+
Potential ambiguity is resolved by checking the type and structure:
5663
* `typeof value === 'string'`**Reason**
57-
* `typeof value === 'object'`**Configuration Object** (`message` and/or `with`)
64+
* `typeof value === 'object' && value.with !== undefined`**Explicit Config**
65+
* Otherwise (`RegExp`, `Function`, `Object`) → **Validation Matcher**
5866

5967
## Alternatives Considered
6068

0 commit comments

Comments
 (0)