diff --git a/__tests__/label/remove.test.ts b/__tests__/label/remove.test.ts index dfcb3ec5..da171956 100644 --- a/__tests__/label/remove.test.ts +++ b/__tests__/label/remove.test.ts @@ -27,10 +27,11 @@ describe('remove', () => { issueCommentEvent.comment.body = '/remove some-label' const commentContext = new utils.MockContext(issueCommentEvent) + const removeSomeLabel = new utils.ObserveRequest() server.use( http.delete( `${utils.api}/repos/Codertocat/Hello-World/issues/1/labels/some-label`, - utils.mockResponse(200), + utils.mockResponse(200, null, removeSomeLabel), ), http.get( `${utils.api}/repos/Codertocat/Hello-World/issues/1`, @@ -42,21 +43,26 @@ describe('remove', () => { ), ) + const setFailed = vi.spyOn(core, 'setFailed').mockImplementation(() => {}) await handleIssueComment(commentContext) + await expect(removeSomeLabel.called()).resolves.toBe('called') + expect(setFailed).not.toHaveBeenCalled() }) it('removes multiple labels', async () => { issueCommentEvent.comment.body = '/remove some-label some-other-label' const commentContext = new utils.MockContext(issueCommentEvent) + const removeSomeLabel = new utils.ObserveRequest() + const removeSomeOtherLabel = new utils.ObserveRequest() server.use( http.delete( `${utils.api}/repos/Codertocat/Hello-World/issues/1/labels/some-label`, - utils.mockResponse(200), + utils.mockResponse(200, null, removeSomeLabel), ), http.delete( `${utils.api}/repos/Codertocat/Hello-World/issues/1/labels/some-other-label`, - utils.mockResponse(200), + utils.mockResponse(200, null, removeSomeOtherLabel), ), http.get( `${utils.api}/repos/Codertocat/Hello-World/issues/1`, @@ -68,7 +74,12 @@ describe('remove', () => { ), ) + const setFailed = vi.spyOn(core, 'setFailed').mockImplementation(() => {}) await handleIssueComment(commentContext) + // every requested label is removed, not just the first + await expect(removeSomeLabel.called()).resolves.toBe('called') + await expect(removeSomeOtherLabel.called()).resolves.toBe('called') + expect(setFailed).not.toHaveBeenCalled() }) it('fails if commenter is not collaborator', async () => { diff --git a/eslint.config.mjs b/eslint.config.mjs index 55c6c300..e9f0b099 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -9,4 +9,16 @@ export default antfu({ 'node_modules/', '**/node_modules/**/', ], +}, { + files: ['__tests__/**/*.test.ts'], + rules: { + // A test that drives the code but checks nothing passes whatever the code + // does. The extra names are this suite's own assertion helpers: the + // expectRequests/expectWindow family in __tests__/bundle and + // ObserveRequest.called()/notCalled() in __tests__/testUtils.ts, which + // reject on their own when the observed request is missing or present. + 'test/expect-expect': ['error', { + assertFunctionNames: ['expect', 'expect*', '*.called', '*.notCalled'], + }], + }, })