felte
felte copied to clipboard
Felte form blows up on submit when testing in Solid.js
Describe the bug
When attempting to unit test one of my Solid components that is using Felte, I get a crash on submit:
Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Unhandled Rejection ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
❯ exports.convert node_modules/jsdom/lib/jsdom/living/generated/Event.js:22:9
❯ HTMLFormElement.dispatchEvent node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:236:24
❯ HTMLFormElement.handleSubmit node_modules/@felte/core/dist/esm/helpers.js:228:78
TypeError: Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.
I was able to reproduce with a very simple test:
function MyComponent(args) {
const { form } = createForm({
onSubmit: args.onSubmit,
});
return (
<>
<form use:form>
<input type="text" name="value" data-testid="name" />
<input type="submit" name="value" data-testid="submit" />
</form>
</>
);
}
describe('doing a basic form submit', () => {
afterEach(cleanup);
it('should not blow up', async () => {
const onSubmit = (values) => {
console.log(values);
};
const { findByTestId, unmount } = render(
<MyComponent onSubmit={onSubmit} />
);
const nameField = await findByTestId('name');
nameField.value = 'Testing';
const submit = await findByTestId('submit');
submit.click();
unmount();
});
});
This is with the latest version of Solid, vite, and jsdom.
Which package/s are you using?
@felte/solid (SolidJS)
Environment
- OS: Docker, node:19.3.0-alpine
- Browser: No browser, running in jsdom
- Version: @felte/solid [email protected]
To reproduce
Run the tests written above.
Small reproduction example
No response
Screenshots
No response
Additional context
No response