Skip to content

Commit 7367cfa

Browse files
committed
resolve message on assertion errors
1 parent f537328 commit 7367cfa

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

e2e/__tests__/failureDetailsProperty.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ test('that the failureDetails property is set', () => {
3434
"matcherResult": Object {
3535
"actual": true,
3636
"expected": false,
37+
"message": "expect(received).toBe(expected) // Object.is equality
38+
39+
Expected: false
40+
Received: true",
3741
"name": "toBe",
3842
"pass": false,
3943
},
@@ -59,6 +63,10 @@ test('that the failureDetails property is set', () => {
5963
"matcherResult": Object {
6064
"actual": true,
6165
"expected": false,
66+
"message": "expect(received).toBe(expected) // Object.is equality
67+
68+
Expected: false
69+
Received: true",
6270
"name": "toBe",
6371
"pass": false,
6472
},
@@ -90,6 +98,18 @@ test('that the failureDetails property is set', () => {
9098
\\"p1\\": \\"hello\\",
9199
\\"p2\\": \\"sunshine\\",
92100
}",
101+
"message": "expect(received).toMatchInlineSnapshot(snapshot)
102+
103+
Snapshot name: \`my test a snapshot failure 1\`
104+
105+
- Snapshot - 1
106+
+ Received + 1
107+
108+
Object {
109+
\\"p1\\": \\"hello\\",
110+
- \\"p2\\": \\"sunshine\\",
111+
+ \\"p2\\": \\"world\\",
112+
}",
93113
"name": "toMatchInlineSnapshot",
94114
"pass": false,
95115
},
@@ -169,6 +189,10 @@ test('that the failureDetails property is set', () => {
169189
"matcherResult": Object {
170190
"actual": true,
171191
"expected": false,
192+
"message": "expect(received).toBe(expected) // Object.is equality
193+
194+
Expected: false
195+
Received: true",
172196
"name": "toBe",
173197
"pass": false,
174198
},
@@ -179,6 +203,10 @@ test('that the failureDetails property is set', () => {
179203
"matcherResult": Object {
180204
"actual": true,
181205
"expected": false,
206+
"message": "expect(received).toBe(expected) // Object.is equality
207+
208+
Expected: false
209+
Received: true",
182210
"name": "toBe",
183211
"pass": false,
184212
},
@@ -195,6 +223,18 @@ test('that the failureDetails property is set', () => {
195223
\\"p1\\": \\"hello\\",
196224
\\"p2\\": \\"sunshine\\",
197225
}",
226+
"message": "expect(received).toMatchInlineSnapshot(snapshot)
227+
228+
Snapshot name: \`my test a snapshot failure 1\`
229+
230+
- Snapshot - 1
231+
+ Received + 1
232+
233+
Object {
234+
\\"p1\\": \\"hello\\",
235+
- \\"p2\\": \\"sunshine\\",
236+
+ \\"p2\\": \\"world\\",
237+
}",
198238
"name": "toMatchInlineSnapshot",
199239
"pass": false,
200240
},

packages/expect/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import type {
5050
import {iterableEquality, subsetEquality} from './utils';
5151

5252
class JestAssertionError extends Error {
53-
matcherResult?: SyncExpectationResult;
53+
matcherResult?: Omit<SyncExpectationResult, 'message'> & {message: string};
5454
}
5555

5656
const isPromise = <T extends any>(obj: any): obj is PromiseLike<T> =>
@@ -293,7 +293,7 @@ const makeThrowingMatcher = (
293293
// Passing the result of the matcher with the error so that a custom
294294
// reporter could access the actual and expected objects of the result
295295
// for example in order to display a custom visual diff
296-
error.matcherResult = result;
296+
error.matcherResult = {...result, message};
297297

298298
if (throws) {
299299
throw error;

0 commit comments

Comments
 (0)