mirror of https://github.com/sveltejs/svelte
Merge branch 'proposal/bind_value_as_date' of https://github.com/colincasey/svelte into colincasey-proposal/bind_value_as_date
commit
5ed8b03c74
@ -0,0 +1,55 @@
|
||||
const SEP_03_2019_INPUT_VALUE = '2019-09-03';
|
||||
const SEP_03_2019_DATE_VALUE = new Date(SEP_03_2019_INPUT_VALUE);
|
||||
|
||||
const OCT_07_2019_INPUT_VALUE = '2019-10-07';
|
||||
const OCT_07_2019_DATE_VALUE = new Date(OCT_07_2019_INPUT_VALUE);
|
||||
|
||||
export default {
|
||||
props: {
|
||||
date: SEP_03_2019_DATE_VALUE
|
||||
},
|
||||
|
||||
html: `
|
||||
<input type=date>
|
||||
<p>[object Date] ${SEP_03_2019_DATE_VALUE}</p>
|
||||
`,
|
||||
|
||||
ssrHtml: `
|
||||
<input type=date value='${SEP_03_2019_INPUT_VALUE}'>
|
||||
<p>[object Date] ${SEP_03_2019_DATE_VALUE}</p>
|
||||
`,
|
||||
|
||||
async test({ assert, component, target, window }) {
|
||||
const input = target.querySelector('input');
|
||||
assert.equal(input.value, SEP_03_2019_INPUT_VALUE);
|
||||
assert.equal(component.date.toString(), SEP_03_2019_DATE_VALUE.toString());
|
||||
|
||||
const event = new window.Event('input');
|
||||
|
||||
input.value = OCT_07_2019_INPUT_VALUE;
|
||||
await input.dispatchEvent(event);
|
||||
|
||||
assert.equal(component.date.toString(), OCT_07_2019_DATE_VALUE.toString());
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<input type='date'>
|
||||
<p>[object Date] ${OCT_07_2019_DATE_VALUE}</p>
|
||||
`);
|
||||
|
||||
component.date = SEP_03_2019_DATE_VALUE;
|
||||
assert.equal(input.value, SEP_03_2019_INPUT_VALUE);
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<input type='date'>
|
||||
<p>[object Date] ${SEP_03_2019_DATE_VALUE}</p>
|
||||
`);
|
||||
|
||||
// empty string should be treated as undefined
|
||||
input.value = '';
|
||||
await input.dispatchEvent(event);
|
||||
|
||||
assert.equal(component.date, undefined);
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<input type='date'>
|
||||
<p>[object Undefined] undefined</p>
|
||||
`);
|
||||
},
|
||||
};
|
@ -0,0 +1,6 @@
|
||||
<script>
|
||||
export let date;
|
||||
</script>
|
||||
|
||||
<input type='date' bind:value={date}>
|
||||
<p>{Object.prototype.toString.call(date)} {date}</p>
|
Loading…
Reference in new issue