mirror of https://github.com/sveltejs/svelte
commit
240319c90e
@ -1,5 +0,0 @@
|
||||
---
|
||||
question: Is svelte.dev down?
|
||||
---
|
||||
|
||||
Probably not, but it's possible. If you can't seem to access any `.dev` sites, check out [this SuperUser question and answer](https://superuser.com/q/1413402).
|
@ -0,0 +1,34 @@
|
||||
export default {
|
||||
props: {
|
||||
items: [],
|
||||
selected: 'two'
|
||||
},
|
||||
|
||||
html: `
|
||||
<select></select>
|
||||
<p>selected: two</p>
|
||||
`,
|
||||
|
||||
ssrHtml: `
|
||||
<select value="two"></select>
|
||||
<p>selected: two</p>
|
||||
`,
|
||||
|
||||
test({ assert, component, target }) {
|
||||
component.items = [ 'one', 'two', 'three' ];
|
||||
|
||||
const options = target.querySelectorAll('option');
|
||||
assert.ok(!options[0].selected);
|
||||
assert.ok(options[1].selected);
|
||||
assert.ok(!options[2].selected);
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<select>
|
||||
<option value='one'>one</option>
|
||||
<option value='two'>two</option>
|
||||
<option value='three'>three</option>
|
||||
</select>
|
||||
<p>selected: two</p>
|
||||
`);
|
||||
}
|
||||
};
|
@ -0,0 +1,12 @@
|
||||
<script>
|
||||
export let selected;
|
||||
export let items;
|
||||
</script>
|
||||
|
||||
<select bind:value={selected}>
|
||||
{#each items as item}
|
||||
<option>{item}</option>
|
||||
{/each}
|
||||
</select>
|
||||
|
||||
<p>selected: {selected || 'nothing'}</p>
|
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
export let action;
|
||||
</script>
|
||||
|
||||
<div use:action />
|
@ -0,0 +1,21 @@
|
||||
export default {
|
||||
test({ assert, component, raf }) {
|
||||
assert.equal(component.count, 0);
|
||||
|
||||
component.arr = ["2"];
|
||||
|
||||
assert.equal(component.count, 1);
|
||||
|
||||
component.arr = ["1", "2"];
|
||||
|
||||
assert.equal(component.count, 2);
|
||||
|
||||
component.arr = ["2", "1"];
|
||||
|
||||
assert.equal(component.count, 2);
|
||||
|
||||
component.arr = [];
|
||||
|
||||
assert.equal(component.count, 0);
|
||||
},
|
||||
};
|
@ -0,0 +1,17 @@
|
||||
<script>
|
||||
import Component from "./Component.svelte";
|
||||
export let arr = [];
|
||||
export let count = 0;
|
||||
function action(node, params) {
|
||||
count += 1;
|
||||
return {
|
||||
destroy() {
|
||||
count -= 1;
|
||||
}
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
{#each arr as item (item)}
|
||||
<Component {action} />
|
||||
{/each}
|
@ -0,0 +1,39 @@
|
||||
export default {
|
||||
async test({ assert, component, target, window }) {
|
||||
const [input1, input2] = target.querySelectorAll('input');
|
||||
const select = target.querySelector('select');
|
||||
const [option1, option2] = select.childNodes;
|
||||
|
||||
let selections = Array.from(select.selectedOptions);
|
||||
assert.equal(selections.length, 2);
|
||||
assert.ok(selections.includes(option1));
|
||||
assert.ok(selections.includes(option2));
|
||||
|
||||
const event = new window.Event('change');
|
||||
|
||||
input1.checked = false;
|
||||
await input1.dispatchEvent(event);
|
||||
|
||||
selections = Array.from(select.selectedOptions);
|
||||
assert.equal(selections.length, 1);
|
||||
assert.ok(!selections.includes(option1));
|
||||
assert.ok(selections.includes(option2));
|
||||
|
||||
input2.checked = false;
|
||||
await input2.dispatchEvent(event);
|
||||
input1.checked = true;
|
||||
await input1.dispatchEvent(event);
|
||||
|
||||
selections = Array.from(select.selectedOptions);
|
||||
assert.equal(selections.length, 1);
|
||||
assert.ok(selections.includes(option1));
|
||||
assert.ok(!selections.includes(option2));
|
||||
|
||||
component.spread = { value: ['Hello', 'World'] };
|
||||
|
||||
selections = Array.from(select.selectedOptions);
|
||||
assert.equal(selections.length, 2);
|
||||
assert.ok(selections.includes(option1));
|
||||
assert.ok(selections.includes(option2));
|
||||
}
|
||||
};
|
@ -0,0 +1,12 @@
|
||||
<script>
|
||||
let value = ['Hello', 'World'];
|
||||
export let spread = {};
|
||||
</script>
|
||||
|
||||
<select multiple {value} {...spread}>
|
||||
<option>Hello</option>
|
||||
<option>World</option>
|
||||
</select>
|
||||
|
||||
<input type="checkbox" value="Hello" bind:group={value}>
|
||||
<input type="checkbox" value="World" bind:group={value}>
|
Loading…
Reference in new issue