mirror of https://github.com/sveltejs/svelte
use value check instead of guard for number inputs (#4689)
parent
467fc84d7d
commit
7ac3e6021a
@ -0,0 +1,31 @@
|
|||||||
|
export default {
|
||||||
|
test({ assert, target, window, component }) {
|
||||||
|
const input = target.querySelector("input");
|
||||||
|
const inputEvent = new window.InputEvent("input");
|
||||||
|
assert.equal(component.value, 5);
|
||||||
|
assert.equal(input.value, "5");
|
||||||
|
|
||||||
|
input.value = "5.";
|
||||||
|
input.dispatchEvent(inputEvent);
|
||||||
|
|
||||||
|
// input type number has value === "" if ends with dot/comma
|
||||||
|
assert.equal(component.value, undefined);
|
||||||
|
assert.equal(input.value, "");
|
||||||
|
|
||||||
|
input.value = "5.5";
|
||||||
|
input.dispatchEvent(inputEvent);
|
||||||
|
|
||||||
|
assert.equal(component.value, 5.5);
|
||||||
|
assert.equal(input.value, "5.5");
|
||||||
|
|
||||||
|
input.value = "5.50";
|
||||||
|
input.dispatchEvent(inputEvent);
|
||||||
|
|
||||||
|
assert.equal(component.value, 5.5);
|
||||||
|
assert.equal(input.value, "5.50");
|
||||||
|
|
||||||
|
component.value = 1;
|
||||||
|
assert.equal(component.value, 1);
|
||||||
|
assert.equal(input.value, "1");
|
||||||
|
},
|
||||||
|
};
|
@ -0,0 +1,5 @@
|
|||||||
|
<script>
|
||||||
|
export let value = 5;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<input type="number" bind:value />
|
Loading…
Reference in new issue