You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/test/runtime/samples/await-then-destruct-object/_config.js

64 lines
1.0 KiB

export default {
props: {
thePromise: new Promise(resolve => {})
},
html: `
loading...
`,
async test({ assert, component, target }) {
await (component.thePromise = Promise.resolve({ error: 'error message' }));
assert.htmlEqual(
target.innerHTML,
`
<p>error: error message</p>
<p>result: undefined</p>
`
);
await (component.thePromise = Promise.resolve({ result: '42' }));
assert.htmlEqual(
target.innerHTML,
`
<p>error: undefined</p>
<p>result: 42</p>
`
);
try {
await (component.thePromise = Promise.reject({
error: { message: 'oops', code: '123' }
}));
} catch (e) {
// do nothing
}
assert.htmlEqual(
target.innerHTML,
`
<p>message: oops</p>
<p>code: 123</p>
`
);
try {
await (component.thePromise = Promise.reject({
error: { message: 'timeout', code: '456' }
}));
} catch (e) {
// do nothing
}
assert.htmlEqual(
target.innerHTML,
`
<p>message: timeout</p>
<p>code: 456</p>
`
);
}
};