Use `event.key` in tests instead of deprecated event.which

pull/4758/head
Daniel Imfeld 5 years ago
parent 61776ac8b4
commit 0048077161

@ -4,7 +4,7 @@ export default {
test({ assert, component, target, window }) { test({ assert, component, target, window }) {
const input = target.querySelector('input'); const input = target.querySelector('input');
const event = new window.KeyboardEvent('keydown', { const event = new window.KeyboardEvent('keydown', {
which: 13 key: 'Enter'
}); });
let blurred = false; let blurred = false;

@ -1,7 +1,7 @@
<script> <script>
function enter(node, callback) { function enter(node, callback) {
function handleKeydown(event) { function handleKeydown(event) {
if (event.which === 13) { if (event.key === 'Enter') {
callback(event); callback(event);
} }
} }
@ -16,4 +16,4 @@
} }
</script> </script>
<input use:enter='{e => e.target.blur()}'> <input use:enter='{e => e.target.blur()}'>

@ -3,7 +3,7 @@ export default {
async test({ assert, component, target, window }) { async test({ assert, component, target, window }) {
const event = new window.KeyboardEvent('keydown', { const event = new window.KeyboardEvent('keydown', {
which: 27 key: 'Escape'
}); });
await window.dispatchEvent(event); await window.dispatchEvent(event);

@ -3,7 +3,7 @@
function esc(node, callback) { function esc(node, callback) {
function onKeyDown(event) { function onKeyDown(event) {
if (event.which === 27) callback(event); if (event.key === 'Escape') callback(event);
} }
node.addEventListener('keydown', onKeyDown); node.addEventListener('keydown', onKeyDown);
return { return {
@ -16,4 +16,4 @@
<svelte:window use:esc="{() => escaped = true}" /> <svelte:window use:esc="{() => escaped = true}" />
<p>escaped: {escaped}</p> <p>escaped: {escaped}</p>

Loading…
Cancel
Save