Closed kimroen closed 3 months ago
I believe this is handled in this variable in module scope, so resetting module state between each test could be one way of getting around this. This would slow down the test suite a lot though.
Thank you for your good report/feature request.
How about the API:
import { Tools, Form } from '@dnb/eufemia/extensions/forms'
beforeEach(() => {
Tools.formReset('unique-id')
})
What would you recommend, like:
In a meeting the suggestion goes towards: Form.clearData
Sounds good to me! The "reset" wording kind of implies that it'll go back to the default values, but it's probably not going to do that, right? You would need to render the form again to get the default values back in there.
Also agreed on keeping it on Form
instead of ~introducing Tools
~ I saw afterwards that we already have Tools
, but I still agree 😊
:tada: This issue has been resolved in version 10.44.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
🐛 Bug Report
When a form has been defined with an
id
, the contents of the form persists even when react re-mounts the application. This sounds like it might be the intention, so I don't necessarily want to call it a bug, but wanted to raise it since it causes problems for us.We have a form with an id that we render in a test. When we run multiple tests, the state of the form persists from the first test to the next.
To Reproduce
Make a test file with this content (sorry, I couldn't make testing-library run properly in codesandbox):
The second test fails, because the value of the field is "SallyJohn", and not "John".
Expected behavior
The form does not retain the entered data between tests. Either by some way of resetting the state between tests, or by providing a way of scoping it to a context (perhaps the
EufemiaProvider
).Eufemia Version
Node.js: 10.43.0