mirror of https://github.com/sveltejs/svelte
parent
c19542b634
commit
a29b185d85
@ -0,0 +1,14 @@
|
||||
import { Node } from 'estree';
|
||||
|
||||
export default function replace_object(node: Node, replacement: Node) {
|
||||
if (node.type === 'Identifier') return replacement;
|
||||
|
||||
const ancestor = node;
|
||||
let parent;
|
||||
while (node.type === 'MemberExpression') {
|
||||
parent = node;
|
||||
node = node.object;
|
||||
}
|
||||
parent.object = replacement;
|
||||
return ancestor;
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
export default {
|
||||
html: `
|
||||
Hello
|
||||
<input />
|
||||
`,
|
||||
ssrHtml: `
|
||||
Hello
|
||||
<input value="Hello"/>
|
||||
`,
|
||||
async test({ assert, target, window }) {
|
||||
const input = target.querySelector("input");
|
||||
input.value = "abcd";
|
||||
await input.dispatchEvent(new window.Event("input"));
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
abcd
|
||||
<input />
|
||||
`
|
||||
);
|
||||
},
|
||||
};
|
@ -0,0 +1,10 @@
|
||||
<script>
|
||||
let a = [
|
||||
{ a: 'Hello' }
|
||||
];
|
||||
</script>
|
||||
|
||||
{#each a as { a }}
|
||||
{a}
|
||||
<input bind:value={a} />
|
||||
{/each}
|
@ -0,0 +1,105 @@
|
||||
export default {
|
||||
html: `
|
||||
<div>
|
||||
Hello World
|
||||
<input />
|
||||
<input />
|
||||
</div>
|
||||
<div>
|
||||
Sapper App
|
||||
<input />
|
||||
<input />
|
||||
</div>
|
||||
`,
|
||||
|
||||
ssrHtml: `
|
||||
<div>
|
||||
Hello World
|
||||
<input value="Hello"/>
|
||||
<input value="World"/>
|
||||
</div>
|
||||
<div>
|
||||
Sapper App
|
||||
<input value="Sapper"/>
|
||||
<input value="App"/>
|
||||
</div>
|
||||
`,
|
||||
async test({ assert, target, window }) {
|
||||
const [input1, input2, input3, input4] = target.querySelectorAll("input");
|
||||
input1.value = "Awesome";
|
||||
await input1.dispatchEvent(new window.Event("input"));
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<div>
|
||||
Awesome World
|
||||
<input />
|
||||
<input />
|
||||
</div>
|
||||
<div>
|
||||
Sapper App
|
||||
<input />
|
||||
<input />
|
||||
</div>
|
||||
`
|
||||
);
|
||||
|
||||
input2.value = "Svelte";
|
||||
await input2.dispatchEvent(new window.Event("input"));
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<div>
|
||||
Awesome Svelte
|
||||
<input />
|
||||
<input />
|
||||
</div>
|
||||
<div>
|
||||
Sapper App
|
||||
<input />
|
||||
<input />
|
||||
</div>
|
||||
`
|
||||
);
|
||||
|
||||
input3.value = "Foo";
|
||||
await input3.dispatchEvent(new window.Event("input"));
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<div>
|
||||
Awesome Svelte
|
||||
<input />
|
||||
<input />
|
||||
</div>
|
||||
<div>
|
||||
Foo App
|
||||
<input />
|
||||
<input />
|
||||
</div>
|
||||
`
|
||||
);
|
||||
|
||||
input4.value = "Bar";
|
||||
await input4.dispatchEvent(new window.Event("input"));
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<div>
|
||||
Awesome Svelte
|
||||
<input />
|
||||
<input />
|
||||
</div>
|
||||
<div>
|
||||
Foo Bar
|
||||
<input />
|
||||
<input />
|
||||
</div>
|
||||
`
|
||||
);
|
||||
},
|
||||
};
|
@ -0,0 +1,14 @@
|
||||
<script>
|
||||
let a = [
|
||||
['Hello', 'World'],
|
||||
['Sapper', 'App'],
|
||||
]
|
||||
</script>
|
||||
|
||||
{#each a as a}
|
||||
<div>
|
||||
{a[0]} {a[1]}
|
||||
<input bind:value={a[0]}>
|
||||
<input bind:value={a[1]}>
|
||||
</div>
|
||||
{/each}
|
@ -0,0 +1,64 @@
|
||||
export default {
|
||||
html: `
|
||||
<div>
|
||||
b: Hello
|
||||
<input />
|
||||
</div>
|
||||
<button>Button</button>
|
||||
`,
|
||||
ssrHtml: `
|
||||
<div>
|
||||
b: Hello
|
||||
<input value="Hello" />
|
||||
</div>
|
||||
<button>Button</button>
|
||||
`,
|
||||
async test({ assert, target, window }) {
|
||||
const input = target.querySelector("input");
|
||||
const button = target.querySelector("button");
|
||||
|
||||
input.value = "Awesome";
|
||||
await input.dispatchEvent(new window.Event("input"));
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<div>
|
||||
b: Awesome
|
||||
<input />
|
||||
</div>
|
||||
<button>Button</button>
|
||||
`
|
||||
);
|
||||
|
||||
|
||||
await button.dispatchEvent(new window.MouseEvent("click"));
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<div>
|
||||
c: World
|
||||
<input />
|
||||
</div>
|
||||
<button>Button</button>
|
||||
`
|
||||
);
|
||||
|
||||
assert.equal(input.value, 'World');
|
||||
|
||||
input.value = "Svelte";
|
||||
await input.dispatchEvent(new window.Event("input"));
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<div>
|
||||
c: Svelte
|
||||
<input />
|
||||
</div>
|
||||
<button>Button</button>
|
||||
`
|
||||
);
|
||||
},
|
||||
};
|
@ -0,0 +1,14 @@
|
||||
<script>
|
||||
let a = [
|
||||
{ a: { b: 'Hello', c: 'World' }, key: 'b' },
|
||||
];
|
||||
</script>
|
||||
|
||||
{#each a as { a, key }}
|
||||
<div>
|
||||
{key}: {a[key]}
|
||||
<input bind:value={a[key]}>
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
<button on:click={() => a[0].key = 'c'}>Button</button>
|
@ -0,0 +1,23 @@
|
||||
export default {
|
||||
html: `
|
||||
Hello
|
||||
<input />
|
||||
`,
|
||||
ssrHtml: `
|
||||
Hello
|
||||
<input value="Hello"/>
|
||||
`,
|
||||
async test({ assert, target, window }) {
|
||||
const input = target.querySelector("input");
|
||||
input.value = "abcd";
|
||||
await input.dispatchEvent(new window.Event("input"));
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
abcd
|
||||
<input />
|
||||
`
|
||||
);
|
||||
},
|
||||
};
|
@ -0,0 +1,10 @@
|
||||
<script>
|
||||
let a = [
|
||||
'Hello'
|
||||
];
|
||||
</script>
|
||||
|
||||
{#each a as a}
|
||||
{a}
|
||||
<input bind:value={a} />
|
||||
{/each}
|
Loading…
Reference in new issue