Skip to content

Instantly share code, notes, and snippets.

@nicksteffens
Created April 17, 2019 20:00
Show Gist options
  • Save nicksteffens/89647189301b962aac2faaa420b6a5c6 to your computer and use it in GitHub Desktop.
Save nicksteffens/89647189301b962aac2faaa420b6a5c6 to your computer and use it in GitHub Desktop.
Example of the triggerKeyEvent being actively blocked by the browser.
import { module, test } from "qunit";
import { setupRenderingTest } from "ember-qunit";
import { render, typeIn, triggerKeyEvent } from "@ember/test-helpers";
import hbs from "htmlbars-inline-precompile";
module(
"Integration | Component | data-properties-panel/custom-property-form",
function(hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(async () => {
await render(hbs`<input data-test-input type="text"/>`);
});
test("it should have backspaced input font", async function(assert) {
await typeIn("[data-test-input]", "hello world");
assert.dom("[data-test-input]").hasValue("hello world");
await triggerKeyEvent("[data-test-input]", "keydown", "Backspace");
assert.dom("[data-test-input]").hasValue("hello worl");
});
module("work around", hooks => {
const backspaceHandler = e => {
if (e.key === "Backspace") {
e.srcElement.value = e.srcElement.value.slice(0, -1);
}
};
hooks.beforeEach(function() {
document
.querySelector("[data-test-input]")
.addEventListener("keydown", backspaceHandler);
});
hooks.afterEach(function() {
document
.querySelector("[data-test-input]")
.removeEventListener("keydown", backspaceHandler);
});
test("it should have backspaced input font", async function(assert) {
await typeIn("[data-test-input]", "hello world");
assert.dom("[data-test-input]").hasValue("hello world");
await triggerKeyEvent("[data-test-input]", "keydown", "Backspace");
assert.dom("[data-test-input]").hasValue("hello worl");
});
});
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment