I have a component with a button and a click handler. In my test, I’m trying to simulate pressing Enter on the button, but it won’t fire the click handler. However when I manually do it, it does. Any ideas?
ember g component my-button -gc
<button type="button" {{on "click" this.onClick}}>
Press enter on me
</button>
import Component from '@glimmer/component';
import { action } from '@ember/object';
export default class MyButtonComponent extends Component {
@action
onClick() {
console.log('BOOM');
}
}
module('Integration | Component | my-button', function (hooks) {
setupRenderingTest(hooks);
test('it renders', async function (assert) {
await render(hbs`<MyButton />`);
await focus('button');
await triggerKeyEvent('button', 'keydown', 'Enter');
});
});
The result of the test is that it doesn’t log “BOOM”. However, if I manually do it in the browser, “BOOM” is logged. Any ideas? Thanks in advance!