-
Notifications
You must be signed in to change notification settings - Fork 469
feat(configureTestIdAttribute): add ability to override data-testid [generic config] #164
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
Merged
kentcdodds
merged 5 commits into
testing-library:master
from
RoystonS:pr/configure-testid-generic-config
Nov 29, 2018
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b8c0217
feat(configureTestIdAttribute): add ability to override data-testid
RoystonS a9c61a1
Fix broken export
Royston-Shufflebotham-i2 eaedbde
Add function-based overload to configure()
RoystonS 26cd837
Fix eslint complaint
RoystonS 38b607e
Tidy README & don't rely on unsupported API in tests
RoystonS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// It would be cleaner for this to live inside './queries', but | ||
// other parts of the code assume that all exports from | ||
// './queries' are query functions. | ||
let config = { | ||
testIdAttribute: 'data-testid', | ||
} | ||
|
||
export function configure(configDelta) { | ||
config = { | ||
...config, | ||
...configDelta, | ||
} | ||
} | ||
export function getTestIdAttribute() { | ||
return config.testIdAttribute | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface IConfig { | ||
testIdAttribute: string | ||
} | ||
|
||
export function configure(configDelta: Partial<IConfig>): void |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This looks good to me. My only nit is that I don't think there needs to be a special method to grab just this attribute; export the whole config object or a getConfig function instead.
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.
Configure could also take an update function:
This would be nice if you want to read and extend subobjects or arrays (like the current set of queries) without importing the default value into the host file.
Uh oh!
There was an error while loading. Please reload this page.
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.
This comes from of some of my type-safety background. It's easy to get a silent failure from
getConfig().mistypedConfigKeyName
butgetMistypedConfigKeyFunction()
will always blow. But in this case the code will be protected by a unit test so that shouldn't be an issue. I'll tweak it to agetConfig
function as that's more flexible than merely exposing the whole config.