-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[jest-each] Fix pluralising missing arguments error #6369
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,15 +39,20 @@ export default (cb: Function) => (...args: any) => | |
const keys = getHeadingKeys(templateStrings[0]); | ||
const table = buildTable(data, keys.length, keys); | ||
|
||
if (data.length % keys.length !== 0) { | ||
const missingData = data.length % keys.length; | ||
|
||
if (missingData > 0) { | ||
const error = new Error( | ||
'Not enough arguments supplied for given headings:\n' + | ||
EXPECTED_COLOR(keys.join(' | ')) + | ||
'\n\n' + | ||
'Received:\n' + | ||
RECEIVED_COLOR(pretty(data)) + | ||
'\n\n' + | ||
`Missing ${RECEIVED_COLOR(`${data.length % keys.length}`)} arguments`, | ||
`Missing ${RECEIVED_COLOR(missingData.toString())} ${pluralize( | ||
'argument', | ||
missingData, | ||
)}`, | ||
); | ||
|
||
if (Error.captureStackTrace) { | ||
|
@@ -136,3 +141,6 @@ const applyObjectParams = (obj: any, test: Function) => { | |
|
||
return () => test(obj); | ||
}; | ||
|
||
const pluralize = (word: string, count: number) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about using pluralize from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if it's worth to import whole package though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it didn't seem worth it for such a small function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope |
||
word + (count === 1 ? '' : 's'); |
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.
How about using
snapshot-diff
to only check the difference?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.
Do we use this already in core?