Skip to content

Commit 1665a87

Browse files
committed
test: stop asserting things _inside_ a mocked function
It is bad practice, and for good reason: It makes it hard to verify things when the same, mocked function is called _multiple_ times inside the same test case, and with different parameters that need to be verified, too. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 6c97a50 commit 1665a87

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

__tests__/index.test.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
const mockTriggerWorkflowDispatch = jest.fn(async (_context, _token, owner, repo, workflow_id, ref, inputs) => {
2-
expect(`${owner}/${repo}`).toEqual('gitgitgadget-workflows/gitgitgadget-workflows')
3-
expect(workflow_id).toEqual('sync-ref.yml')
4-
expect(ref).toEqual('main')
5-
expect(inputs).toEqual({ ref: 'refs/heads/next' })
6-
return { html_url: '<the URL to the workflow run>'}
1+
const mockTriggerWorkflowDispatch = jest.fn(async (_context, _token, _owner, _repo, workflow_id, ref, inputs) => {
2+
return { html_url: `<the URL to the workflow ${workflow_id} run on ${ref} with inputs ${JSON.stringify(inputs)}>` }
73
})
84
jest.mock('../GitGitGadget/trigger-workflow-dispatch', () => ({
95
triggerWorkflowDispatch: mockTriggerWorkflowDispatch
@@ -197,7 +193,7 @@ testWebhookPayload('react to `next` being pushed to git/git', 'push', {
197193
}
198194
}, (context) => {
199195
expect(context.res).toEqual({
200-
body: 'push(refs/heads/next): triggered <the URL to the workflow run>'
196+
body: 'push(refs/heads/next): triggered <the URL to the workflow sync-ref.yml run on main with inputs {"ref":"refs/heads/next"}>'
201197
})
202198
expect(mockTriggerWorkflowDispatch).toHaveBeenCalledTimes(1)
203199
expect(mockTriggerWorkflowDispatch.mock.calls[0]).toEqual([

0 commit comments

Comments
 (0)