-
Notifications
You must be signed in to change notification settings - Fork 273
feat: add the value expected in getBy error messages #550
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
feat: add the value expected in getBy error messages #550
Conversation
…und with text 'bla'")
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.
Nice work @sregg! 👍
I've added some suggestions for improving code readability.
src/helpers/getByAPI.js
Outdated
`${prepareErrorMessage(error)} with text '${ | ||
typeof text === 'string' ? text : text.toString() | ||
}'`, |
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.
`${prepareErrorMessage(error)} with text '${ | |
typeof text === 'string' ? text : text.toString() | |
}'`, | |
`${prepareErrorMessage(error)} with text '${text}'`, |
We should probably be able to the if condition, sa template string should do the checks & toString() call for us.
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.
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.
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.
@sregg doing text.toString()
or String(text)
(generally safer) is the way to go here, yea 👍
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.
Btw, I think that prepareErrorMessage
function is a perfect place for handling this extra text. Similar to what you have in a test here: https://github.com/callstack/react-native-testing-library/pull/550/files#diff-4246008ab708750218ff9e41118401a1R14
src/helpers/getByAPI.js
Outdated
`${prepareErrorMessage(error)} with placeholder text '${ | ||
typeof placeholder === 'string' ? placeholder : placeholder.toString() | ||
}'`, |
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.
`${prepareErrorMessage(error)} with placeholder text '${ | |
typeof placeholder === 'string' ? placeholder : placeholder.toString() | |
}'`, | |
`${prepareErrorMessage(error)} with placeholder '${placeholder}'`, |
We should probably be able to the if condition, sa template string should do the checks & toString() call for us.
src/helpers/getByAPI.js
Outdated
`${prepareErrorMessage(error)} with display value '${ | ||
typeof displayValue === 'string' | ||
? displayValue | ||
: displayValue.toString() | ||
}'`, |
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.
`${prepareErrorMessage(error)} with display value '${ | |
typeof displayValue === 'string' | |
? displayValue | |
: displayValue.toString() | |
}'`, | |
`${prepareErrorMessage(error)} with display value '${displayValue}'`, |
We should probably be able to the if condition, sa template string should do the checks & toString() call for us.
src/helpers/makeQuery.js
Outdated
`${prepareErrorMessage(error)} with ${name} '${ | ||
typeof matcher === 'string' ? matcher : JSON.stringify(matcher) || '' | ||
}'`, |
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.
What is the reason for using JSON.stringify
instead of toString
like in other places?
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.
Co-authored-by: Maciej Jastrzebski <[email protected]>
src/helpers/makeQuery.js
Outdated
throw new ErrorWithStack('No instances found', getAllBy); | ||
throw new ErrorWithStack( | ||
`No instances found with ${name} '${ | ||
typeof matcher === 'string' ? matcher : JSON.stringify(matcher) || '' |
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.
we have pretty-format
in our deps, so let's use that with {min: true}
option set: https://github.com/facebook/jest/tree/master/packages/pretty-format#usage-with-options
@thymikee I addressed your comments in my latest commit |
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.
👍
Thank you! |
Implements #549
Summary
Add the value that was expected in error message for the following methods:
getByText('bla')
=> No instances found with text 'bla'getByPlaceholderText('bla')
=> No instances found with placeholder text 'bla'getByDisplayValue('bla')
=> No instances found with display value 'bla'getByA11yLabel('bla')
=> No instances found with accessibilityLabel 'bla'getByA11yHint('bla')
=> No instances found with accessibilityHint 'bla'getByA11yRole('bla')
=> No instances found with accessibilityRole 'bla'getByA11yStates('bla')
=> No instances found with accessibilityStates 'bla'getByA11yState({ disabled: true})
=> No instances found with accessibilityState '{"disabled":true}'getByA11yValue({ min: 50 })
=> No instances found with accessibilityValue '{"min":50}'Test plan
I updated some tests to expect the new error message