mirror of https://github.com/sveltejs/svelte
Merge pull request #1049 from sveltejs/gh-1032
fix data references in event handlers inside await-then-catchpull/1050/head
commit
a3d8425ddc
@ -0,0 +1,45 @@
|
||||
let fulfil;
|
||||
let thePromise = new Promise(f => {
|
||||
fulfil = f;
|
||||
});
|
||||
|
||||
export default {
|
||||
data: {
|
||||
thePromise
|
||||
},
|
||||
|
||||
html: `
|
||||
<p>loading...</p>
|
||||
`,
|
||||
|
||||
test(assert, component, target, window) {
|
||||
fulfil(42);
|
||||
|
||||
return thePromise
|
||||
.then(() => {
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<button>click me</button>
|
||||
`);
|
||||
|
||||
const { button } = component.refs;
|
||||
|
||||
const click = new window.MouseEvent('click');
|
||||
button.dispatchEvent(click);
|
||||
|
||||
assert.equal(component.get('clicked'), 42);
|
||||
|
||||
thePromise = Promise.resolve(43);
|
||||
component.set({ thePromise });
|
||||
|
||||
return thePromise;
|
||||
})
|
||||
.then(() => {
|
||||
const { button } = component.refs;
|
||||
|
||||
const click = new window.MouseEvent('click');
|
||||
button.dispatchEvent(click);
|
||||
|
||||
assert.equal(component.get('clicked'), 43);
|
||||
});
|
||||
}
|
||||
};
|
@ -0,0 +1,7 @@
|
||||
{{#await thePromise}}
|
||||
<p>loading...</p>
|
||||
{{then theValue}}
|
||||
<button ref:button on:click='set({ clicked: theValue })'>click me</button>
|
||||
{{catch theError}}
|
||||
<p>oh no! {{theError.message}}</p>
|
||||
{{/await}}
|
Loading…
Reference in new issue