You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The imask package isn't able to recognize an contenteditable element in Jest unit testing. If I use an HTMLDivElement with mask, he work perfectly in browser but when executed in JSDOM, the error value should be a string will be trown.
This happens because JSDOM don't implement contenteditable API, that means HTMLElement.isContentEditable will be always undefined, what causes this validation to return false. Then the library thinks that my element is actually a HTMLInputElement, making the value search look for value property instead textContent property, like expected. This whole scenario what levers to the error mentioned above.
To Reproduce
To reproduce, just run npm run test. Code Sandbox
Expected behavior
The element rendered in fake DOM at tests behave like in browser DOM.
Environment:
OS: Windows 11
Browser: Chrome
Version: 125.0.6422.113
IMask version: 7.6.1
Framework: React 18 and Jest 29
Additional context
Even that I believe that is not an error of yours library, I do believe that is not intentional behavior and the README could have a disclaimer about that problem (JSDOM missing suport for contenteditable). If you are interested in provide a solution to make the tests easier for consumers, I would suggest to change this line from:
Describe the bug
The
imask
package isn't able to recognize an contenteditable element in Jest unit testing. If I use anHTMLDivElement
with mask, he work perfectly in browser but when executed in JSDOM, the errorvalue should be a string
will be trown.This happens because JSDOM don't implement contenteditable API, that means
HTMLElement.isContentEditable
will be alwaysundefined
, what causes this validation to returnfalse
. Then the library thinks that my element is actually a HTMLInputElement, making the value search look forvalue
property insteadtextContent
property, like expected. This whole scenario what levers to the error mentioned above.To Reproduce
To reproduce, just run
npm run test
. Code SandboxExpected behavior
The element rendered in fake DOM at tests behave like in browser DOM.
Environment:
Additional context
Even that I believe that is not an error of yours library, I do believe that is not intentional behavior and the README could have a disclaimer about that problem (JSDOM missing suport for contenteditable). If you are interested in provide a solution to make the tests easier for consumers, I would suggest to change this line from:
to:
Manually changing this line at your library dist code, my test pass.
The text was updated successfully, but these errors were encountered: