fix: toFill doesn't empty contents when given an empty string #381
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.
Summary
this fixes #372 which is an issue when trying to override an input value with
toFill
https://github.com/smooth-code/jest-puppeteer/blob/5a4eb5b8a9e6cf4bddebc49f1794381190ae4e51/packages/expect-puppeteer/src/matchers/toFill.js#L3 with an empty string''
.You would expect this behavior for multiple reasons; the method is called
toFill
which indicates theinput
is filled with any content (including empty content) you provide; the behavior is exactly that when used with non-empty strings.The reason this happens is that
toFill
useselementHandle.type(text[, options])
https://github.com/smooth-code/jest-puppeteer/blob/5a4eb5b8a9e6cf4bddebc49f1794381190ae4e51/packages/expect-puppeteer/src/matchers/toFill.js#L11 (source) which will type any characters passed via a string. An empty string is treated as no characters typed, sotoFill
simply highlights the input content and subsequently does nothing.This proposes fixing this by pressing
Backspace
after selecting the content and typing, which will consistently empty and fill the input.Test plan
I added a test which failed, to prove that this was a real issue. To reproduce check out 4d961d3, run the suite and you should see that it fails, then check out 23526f3 and it succeeds