Skip to content

Commit 6d74b49

Browse files
mixelburgclaudehi-ogawa
authored
fix(expect): soft assertions continue after .resolves/.rejects promise errors (#9843)
Co-authored-by: Maks Pikov <mixelburg@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Hiroshi Ogawa <hi.ogawa.zz@gmail.com>
1 parent 54f2660 commit 6d74b49

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

packages/expect/src/jest-expect.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
11281128
promise,
11291129
createAssertionMessage(utils, this, !!args.length),
11301130
error,
1131+
utils.flag(this, 'soft'),
11311132
)
11321133
}
11331134
},
@@ -1203,6 +1204,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
12031204
promise,
12041205
createAssertionMessage(utils, this, !!args.length),
12051206
error,
1207+
utils.flag(this, 'soft'),
12061208
)
12071209
}
12081210
},

test/cli/fixtures/expect-soft/expects/soft.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,29 @@ test('promise with expect.extend', async () => {
7575
await expect.soft(2 + 2).toBeAsync(3);
7676
});
7777

78+
test('promise rejection', async () => {
79+
await expect
80+
.soft(
81+
Promise.resolve().then(() => {
82+
throw new Error('boom 1st')
83+
}),
84+
)
85+
.resolves.toBe('1st')
86+
87+
await expect
88+
.soft(
89+
Promise.resolve().then(() => {
90+
throw new Error('boom 2nd')
91+
}),
92+
)
93+
.resolves.toBe('2nd')
94+
})
95+
96+
test('promise resolved instead of rejecting', async () => {
97+
await expect.soft(Promise.resolve('value 1')).rejects.toBe('1st')
98+
await expect.soft(Promise.resolve('value 2')).rejects.toBe('2nd')
99+
})
100+
78101
test('passed', () => {
79102
expect.soft(1).toEqual(1)
80103
expect(10).toEqual(10)

test/cli/test/expect-soft.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ describe('expect.soft', () => {
4545
expect.soft(stderr).toContain('Error: expected 4 to be 3')
4646
})
4747

48+
test('promise rejection', async () => {
49+
const { stderr } = await run()
50+
// both assertions should execute (not abort after first rejection)
51+
expect.soft(stderr).toContain('promise rejected "Error: boom 1st" instead of resolving')
52+
expect.soft(stderr).toContain('promise rejected "Error: boom 2nd" instead of resolving')
53+
})
54+
55+
test('promise resolved instead of rejecting', async () => {
56+
const { stderr } = await run()
57+
// both assertions should execute
58+
expect.soft(stderr).toContain('promise resolved "\'value 1\'" instead of rejecting')
59+
expect.soft(stderr).toContain('promise resolved "\'value 2\'" instead of rejecting')
60+
})
61+
4862
test('passed', async () => {
4963
const { stdout } = await run()
5064
expect.soft(stdout).toContain('soft.test.ts > passed')

0 commit comments

Comments
 (0)