-
Notifications
You must be signed in to change notification settings - Fork 336
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
Throw ElementError
for missing elements during Character count instantiation
#4261
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ac66ad5
Add throwing of error when textarea is not of the right type
romaricpascal 1b7d2f6
Add throwing of error when the textarea description is missing
romaricpascal 0c3fb2d
Fix Character count's JSDOM tests
romaricpascal adc0380
Expand the use of `textContent` rather than `innerText` to the other …
romaricpascal f28eee0
Remove quotes around type in ElementError message
romaricpascal 808f7ec
Remove need for cloning helper in Character Count JSDOM tests
romaricpascal 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -808,10 +808,54 @@ describe('Character count', () => { | |
$module.outerHTML = `<svg data-module="govuk-character-count"></svg>` | ||
} | ||
}) | ||
).rejects.toEqual({ | ||
name: 'ElementError', | ||
message: 'Character count: $module is not an instance of HTMLElement' | ||
}) | ||
}) | ||
|
||
it('throws when the textarea is missing', async () => { | ||
await expect( | ||
renderAndInitialise(page, 'character-count', { | ||
params: examples.default, | ||
beforeInitialisation($module) { | ||
$module.querySelector('.govuk-js-character-count').remove() | ||
} | ||
}) | ||
).rejects.toEqual({ | ||
name: 'ElementError', | ||
message: 'Character count: .govuk-js-character-count not found' | ||
}) | ||
}) | ||
|
||
it('throws when the textarea is not the right type', async () => { | ||
await expect( | ||
renderAndInitialise(page, 'character-count', { | ||
params: examples.default, | ||
beforeInitialisation($module) { | ||
// Replace with a tag that's neither an `<input>` or `<textarea>` | ||
$module.querySelector('.govuk-js-character-count').outerHTML = | ||
'<div class="govuk-js-character-count"></div>' | ||
} | ||
}) | ||
).rejects.toEqual({ | ||
name: 'ElementError', | ||
message: | ||
'Character count: $module is not an instance of "HTMLElement"' | ||
'Character count: .govuk-js-character-count is not of type HTMLTextareaElement or HTMLInputElement' | ||
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. It works 🙌 |
||
}) | ||
}) | ||
|
||
it('throws when the textarea description is missing', async () => { | ||
await expect( | ||
renderAndInitialise(page, 'character-count', { | ||
params: examples.default, | ||
beforeInitialisation($module) { | ||
$module.querySelector('#more-detail-info').remove() | ||
} | ||
}) | ||
).rejects.toEqual({ | ||
name: 'ElementError', | ||
message: 'Character count: #more-detail-info not found' | ||
}) | ||
}) | ||
|
||
|
This file contains 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 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 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 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 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 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 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
Oops, something went wrong.
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.
With (potentially) multiple textarea components on the page, how much do we worry about scoping selectors against their module?
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.
Linking with #4263 (review)
For these "module child" selectors it could be brilliant to show a scope that the browser can inspect
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.
🤔 Yeah, that's probably the component most likely to be on a page multiple times. We recommend to start with a single question per page so that limits the risks. It doesn't completely avoids the possibility of multiple of those on the page (especially if we consider the radios/checkboxes potentially revealing fields). That said, there shouldn't be too many of them on a given page that it's tricky for developers to find back the one that's wonky (either by looking carefully at the page or breaking on error in the devtools). I would say it's not something we should not worry too hard about at the start. We can always dig deeper if we receive feedback.
If we have a simple solution, though, not against adding extra information, but it might be tricky to add that consistently. The element with
data-module
does not really have anything identifiable usually. Here, the$textarea
could provide anid
(but only if it is on the page so nothing if it doesn't exist).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.
Whoops, there wasn't your second message when I started writing mine, sorry. How would users access the
$module
you propose passing as$scope
(it's fine if that part still needs looking into)? Do browsers log extra fields from the errors? thecause
maybe, in browsers that support it (that'd be neat)?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.
One to investigate. Would be amazing if you could hover over
scope
and it highlighted the elementCan leave them off for now if we don't need it
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.
That'd speed debugging indeed, but let's see if people come back needing more pointers to where things happen as I think that'd need a good bit of investigation 😊 Had a quick glance at
cause
, Firefox logs it (only if the element itself, if an object, you getObject {...}
, not expandable), not Chrome, nor Safari (at the time of this message). We could always overridetoString
to log before the message gets computed for display in the console, but seems quite hacky anyway 😆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.
Sorry, not the clearest blurb. I'll (try to) clarify:
cause
are logged (no luck there) and tried a quick hack by overridingtoString
to log before the error message gets computed (can log the element, but a bit hacky).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.
No don't worry, the confused face was wondering why
cause
wasn't loggedOne for another day (and don't want to be Chrome specific) but some nice ideas in:
https://developer.chrome.com/docs/devtools/console/log/