-
Notifications
You must be signed in to change notification settings - Fork 47k
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
(WIP) Use only public API for getNodeForCharacterOffset test #11803
(WIP) Use only public API for getNodeForCharacterOffset test #11803
Conversation
You can check where Then you want to delete it before the test, but restore it after regardless of whether the test passed or not. Something like: const inputDescriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'selectionStart');
const textAreaDescriptor = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'selectionStart');
delete HTMLInputElement.prototype.selectionStart;
delete HTMLTextAreaElement.prototype.selectionStart;
try {
// your test
} finally {
Object.defineProperty(HTMLInputElement, 'selectionStart', inputDescriptor);
Object.defineProperty(HTMLTextAreaElement, 'selectionStart', textAreaDescriptor);
} |
That makes sense – thanks for the tip! I got sick last weekend and didn't have the chance to follow up, but I should be able to send an updated PR in the next couple of days – is this ok? |
Sure, get well! |
Hi, @gaearon – Sorry for the delay – the last weeks of the year are hectic around here. I've been trying to come up with an approach for writing these tests via public API, but it's a bit harder than I imagined at first (I'm still very motivated to move forward, though 😄) I've made the changes you've requested, and even managed to trigger actual calls to
Any insights on how I can move forward? Thanks for the help and patience :) [Also, please don't mind the messy code, I was just trying to illustrate my reasoning] |
We've updated jsdom, could you try again? |
Awesome! I’ll try again, thanks for the update :) |
Hi, @gaearon – It still seems like I can try to figure something out with the jsdom guys, if you believe that's a good idea. Otherwise, do you have any suggestions on how we can alternatively approach this test? Please let me know your thoughts. |
@accordeiro I've also found myself struggling with the lack of a selection API in JSDom in the past. Is there an upstream issue to track support for that? As for this PR, I think a bit of mocking might be OK if we:
|
@philipp-spiess there is an upstream issue, but it doesn't look like the DOM selection API implementation is on their roadmap (see jsdom/jsdom#937 for reference). I'll try to do some mocking keeping in mind the two points you've listed – I should have an update until the end of the week, is that ok? |
@accordeiro No worries, take the time you need 😊 We're glad that you still want to work on this issue. Your plan sounds great. Keep us updated! And thanks for linking the upstream issue. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution. |
Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you! |
This PR refers to #11299 - Express more tests via public API.
I’m trying to find a good approach for testing the
getNodeForCharacterOffset()
using only public API.I’ve already mapped the call sequence from the public API to this function:
getNodeForCharacterOffset() @ getNodeForCharacterOffset.js
setOffsets() @ ReactDOMSelection.js
setSelection() @ ReactInputSelection.js
restoreSelection() @ ReactInputSelection.js
Explicitly in this if clause (From ReactInputSelection.js):
DOMRenderer.resetAfterCommit() @ ReactDOM.js
The tests I’ve written so far manage to reach
setSelection() @ ReactInputSelection.js
, but there’s still an if clause insetSelection()
before we actually get togetNodeForCharacterOffset()
, which is:I’m now testing how we could cause the code to trigger the else clause – any insights on how I can achieve this?
Thanks!