Skip to content

Commit f37858e

Browse files
committed
test: simplify unknown listener cleanup
1 parent 723c19f commit f37858e

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

‎packages/devframe/src/in-page-channel/in-page-channel.test.ts‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,19 @@ describe('in-page channel over bring-your-own ports', () => {
120120
}
121121
})
122122

123-
it('reports and rejects listeners for unknown functions', () => {
123+
it('reports and rejects listeners for unknown functions', ({ onTestFinished }) => {
124124
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
125125
const { panel, dispose } = createLinkedPair()
126-
try {
127-
expect(() => {
128-
panel.on('missing' as any, () => {})
129-
}).toThrowError(expect.objectContaining({ name: 'DF0077' }))
130-
expect(warn).toHaveBeenCalledOnce()
131-
expect(warn).toHaveBeenCalledWith(expect.stringContaining('[DF0077]'))
132-
}
133-
finally {
126+
onTestFinished(() => {
134127
dispose()
135128
warn.mockRestore()
136-
}
129+
})
130+
131+
expect(() => {
132+
panel.on('missing' as any, () => {})
133+
}).toThrowError(expect.objectContaining({ name: 'DF0077' }))
134+
expect(warn).toHaveBeenCalledOnce()
135+
expect(warn).toHaveBeenCalledWith(expect.stringContaining('[DF0077]'))
137136
})
138137

139138
it('enforces jsonSerializable payloads with a coded error', async () => {

0 commit comments

Comments
 (0)