-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: consolidate all choose function stuff in util-utils.ts #626
refactor: consolidate all choose function stuff in util-utils.ts #626
Conversation
|
e8ecd26
to
e27f31d
Compare
e27f31d
to
20ca6d7
Compare
20ca6d7
to
a60e2f9
Compare
import { stringTranslateToId } from '../../../../lib/command/command-util.js' | ||
import { | ||
createChooseFn, | ||
type ChooseFunction, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've recently learned about this type
marker (even though it's been around a while!) and have started using it in the PR but I'm realizing now that I've done so rather inconsistently. I plan to do better in the next PR and then open up a discussion with the team in standup to talk about it.
expect(toStringMock).toHaveBeenCalledTimes(1) | ||
expect(toStringMock).toHaveBeenCalledWith() | ||
expect(pushMock).toHaveBeenCalledExactlyOnceWith(['setting', 'setting value']) | ||
expect(toStringMock).toHaveBeenCalledExactlyOnceWith() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the Jest documentation but I'm still not quite sure about something. Is this in fact checking that toStringMock
was called exactly once with no parameters? Or is it not checking parameters since none were supplied?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A call to a With
function that doesn't check the With
seems rather silly so checking for no arguments is the only thing that makes sense to me. It's easy enough to test though; I just removed the argument from a call that had one and I get an error. Here's the output when I remove the argument from line 192 above:
FAIL src/__tests__/lib/command/util/apps-util.test.ts
● buildTableOutput › creates new table with correct options and adds settings
expect(received).toHaveBeenCalledExactlyOnceWith(expected)
Expected mock function to have been called exactly once with [], but it was called with ["setting", "setting value"]
190 | expect.objectContaining({ head: ['Key', 'Value'] }),
191 | )
> 192 | expect(pushMock).toHaveBeenCalledExactlyOnceWith()
| ^
193 | expect(toStringMock).toHaveBeenCalledExactlyOnceWith()
194 | })
195 | })
at Object.<anonymous> (src/__tests__/lib/command/util/apps-util.test.ts:192:20)
Test Suites: 1 failed, 2 passed, 3 total
Tests: 1 failed, 58 passed, 59 total
Snapshots: 0 total
Time: 2.992 s, estimated 6 s
Ran all test suites related to changed files.
Moved all the supporting types and variables for
createChooseFn
into the same file ascreateChooseFn
. Not sure why I didn't do this when I createdcreateChooseFn
. Also updated affected unit tests.