forked from sveltejs/svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
test/runtime/samples/store-invalidation-while-update-1/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
export default { | ||
html: ` | ||
<input> | ||
<div></div> | ||
<div>simple</div> | ||
<button>click me</button> | ||
`, | ||
|
||
async test({ assert, component, target, window }) { | ||
const input = target.querySelector('input'); | ||
const button = target.querySelector('button'); | ||
|
||
const inputEvent = new window.InputEvent('input'); | ||
const clickEvent = new window.MouseEvent('click'); | ||
|
||
input.value = 'foo'; | ||
await input.dispatchEvent(inputEvent); | ||
|
||
assert.htmlEqual(target.innerHTML, ` | ||
<input> | ||
<div>foo</div> | ||
<div>foo</div> | ||
<button>click me</button> | ||
`); | ||
|
||
await button.dispatchEvent(clickEvent); | ||
assert.htmlEqual(target.innerHTML, ` | ||
<input> | ||
<div>foo</div> | ||
<div>clicked</div> | ||
<button>click me</button> | ||
`); | ||
|
||
input.value = 'bar'; | ||
await input.dispatchEvent(inputEvent); | ||
|
||
assert.htmlEqual(target.innerHTML, ` | ||
<input> | ||
<div>bar</div> | ||
<div>bar</div> | ||
<button>click me</button> | ||
`); | ||
} | ||
}; |
20 changes: 20 additions & 0 deletions
20
test/runtime/samples/store-invalidation-while-update-1/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<script> | ||
import {writable} from 'svelte/store'; | ||
function action(node, binding) { | ||
return { | ||
update: (value) => s.set(value), | ||
} | ||
} | ||
let s = writable("simple"); | ||
let v = ""; | ||
function click() { | ||
s.set('clicked'); | ||
} | ||
</script> | ||
|
||
<input bind:value={v} use:action={v}> | ||
<div>{v}</div> | ||
<div>{$s}</div> | ||
<button on:click={click}>click me</button> |
44 changes: 44 additions & 0 deletions
44
test/runtime/samples/store-invalidation-while-update-2/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
export default { | ||
html: ` | ||
<div></div> | ||
<div>simple</div> | ||
<input> | ||
<button>click me</button> | ||
`, | ||
|
||
async test({ assert, component, target, window }) { | ||
const input = target.querySelector('input'); | ||
const button = target.querySelector('button'); | ||
|
||
const inputEvent = new window.InputEvent('input'); | ||
const clickEvent = new window.MouseEvent('click'); | ||
|
||
input.value = 'foo'; | ||
await input.dispatchEvent(inputEvent); | ||
|
||
assert.htmlEqual(target.innerHTML, ` | ||
<div>foo</div> | ||
<div>foo</div> | ||
<input> | ||
<button>click me</button> | ||
`); | ||
|
||
await button.dispatchEvent(clickEvent); | ||
assert.htmlEqual(target.innerHTML, ` | ||
<div>foo</div> | ||
<div>clicked</div> | ||
<input> | ||
<button>click me</button> | ||
`); | ||
|
||
input.value = 'bar'; | ||
await input.dispatchEvent(inputEvent); | ||
|
||
assert.htmlEqual(target.innerHTML, ` | ||
<div>bar</div> | ||
<div>bar</div> | ||
<input> | ||
<button>click me</button> | ||
`); | ||
} | ||
}; |
20 changes: 20 additions & 0 deletions
20
test/runtime/samples/store-invalidation-while-update-2/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<script> | ||
import {writable} from 'svelte/store'; | ||
function action(node, binding) { | ||
return { | ||
update: (value) => s.set(value), | ||
} | ||
} | ||
let s = writable("simple"); | ||
let v = ""; | ||
function click() { | ||
s.set('clicked'); | ||
} | ||
</script> | ||
|
||
<div>{v}</div> | ||
<div>{$s}</div> | ||
<input bind:value={v} use:action={v}> | ||
<button on:click={click}>click me</button> |