ember-test-helpers icon indicating copy to clipboard operation
ember-test-helpers copied to clipboard

`submit()` helper

Open Turbo87 opened this issue 6 years ago • 7 comments

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:

  1. click() on a type="submit" button
  2. 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');
}

Turbo87 avatar May 08 '19 14:05 Turbo87

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?

rwjblue avatar May 08 '19 19:05 rwjblue

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

Turbo87 avatar May 08 '19 19:05 Turbo87

+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.

amk221 avatar May 22 '19 15:05 amk221

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...

rwjblue avatar Jul 02 '19 14:07 rwjblue

I just ran into the issues mentioned above by @Turbo87 and @amk221

@rwjblue Is this enhancement on the roadmap?

LucMorrissette avatar Oct 08 '19 15:10 LucMorrissette

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).

rwjblue avatar Oct 09 '19 18:10 rwjblue

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.

drummy2 avatar Nov 03 '21 14:11 drummy2