`submit()` helper
I would like to propose adding a submit() test helper since submitting forms seems like a regular thing that is done in tests. We currently have two options:
click()on atype="submit"button- use
triggerEvent(..., 'submit')
but they are not entirely obvious and not specific to forms. Having a dedicated submit() helper would make this a lot easier and could also add assertions on whether the passed selector actually belongs to a form, etc.
async function submit(selector) {
await triggerEvent(selector, 'submit');
}
In general, I think this would be useful but I have a few questions:
- What user interaction is being emulated by the helper? I assume that its effectively clicking on a submit button, right?
- What should the selector point to? A form? The button?
What user interaction is being emulated by the helper? I assume that its effectively clicking on a submit button, right?
that, or pressing Enter in a form input
What should the selector point to? A form? The button?
the form, same as for the raw triggerEvent() helper
+1 for this.
I know I can use triggerKeyEvent('button', 'keydown', 13) and triggerEvent('form', 'submit'), but I specifically need to test that pressing enter when a text field is focused will submit the form (i.e. browser's default behaviour).... But triggerEvent('input', 'keydown', 13) will not accomplish that - well it does in the app, but not in the test suite.
I'm game for adding this, but I just want the technical details nailed down (e.g. we need to ensure that what we implement properly emulates pressing enter within the form by testing in "plain html"). Happy to dig into those details in a PR if that is preferable...
I just ran into the issues mentioned above by @Turbo87 and @amk221
@rwjblue Is this enhancement on the roadmap?
Ya, I mentioned above that this seems like a conceptually fine addition. Someone needs to find the time to work on it (e.g. answer the specific technical design questions I listed above, implement, etc).
I can't see any explanation as to why pressing enter on an input doesn't submit the form. The thread suggests a workaround for adding some submit event. This suggests it isn't just a bug and there is some difference with running the application normally vs in test suite. I feel less confident about my testing if there are these odd special circumstances.