From e16e8480fb6449bfa1245070b50355a116e8794f Mon Sep 17 00:00:00 2001 From: Nguyen Tran Date: Mon, 13 Mar 2023 18:32:55 -0400 Subject: [PATCH] Add computed prop tests for const tags --- .../_config.js | 20 +++++++++ .../main.svelte | 25 +++++++++++ .../_config.js | 15 +++++++ .../main.svelte | 42 +++++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 test/runtime/samples/const-tag-await-then-destructuring-computed-props/_config.js create mode 100644 test/runtime/samples/const-tag-await-then-destructuring-computed-props/main.svelte create mode 100644 test/runtime/samples/const-tag-each-destructure-computed-props/_config.js create mode 100644 test/runtime/samples/const-tag-each-destructure-computed-props/main.svelte diff --git a/test/runtime/samples/const-tag-await-then-destructuring-computed-props/_config.js b/test/runtime/samples/const-tag-await-then-destructuring-computed-props/_config.js new file mode 100644 index 0000000000..ef1c60c66c --- /dev/null +++ b/test/runtime/samples/const-tag-await-then-destructuring-computed-props/_config.js @@ -0,0 +1,20 @@ +export default { + html: ` +

4, 12, 60

+ `, + + async test({ component, target, assert }) { + component.permutation = [2, 3, 1]; + await (component.promise1 = Promise.resolve({length: 1, width: 2, height: 3})); + try { + await (component.promise2 = Promise.reject({length: 97, width: 98, height: 99})); + } catch (e) { + // nothing + } + + assert.htmlEqual(target.innerHTML, ` +

2, 11, 2

+

9506, 28811, 98

+ `); + } +}; diff --git a/test/runtime/samples/const-tag-await-then-destructuring-computed-props/main.svelte b/test/runtime/samples/const-tag-await-then-destructuring-computed-props/main.svelte new file mode 100644 index 0000000000..536f4a509a --- /dev/null +++ b/test/runtime/samples/const-tag-await-then-destructuring-computed-props/main.svelte @@ -0,0 +1,25 @@ + + +{#await promise1 then { length, width, height }} + {@const [a, b, c] = permutation} + {@const { [`${a}-Dimensions`]: { [c - 1]: first }, [`${b}-Dimensions`]: { [b - 1]: second }, [`${c}-Dimensions`]: { [a - 1]: third } } = calculate(length, width, height) } +

{first}, {second}, {third}

+{/await} + +{#await promise2 catch { length, width, height }} + {@const [a, b, c] = permutation} + {@const { [`${a}-Dimensions`]: { [c - 1]: first }, [`${b}-Dimensions`]: { [b - 1]: second }, [`${c}-Dimensions`]: { [a - 1]: third } } = calculate(length, width, height) } +

{first}, {second}, {third}

+{/await} diff --git a/test/runtime/samples/const-tag-each-destructure-computed-props/_config.js b/test/runtime/samples/const-tag-each-destructure-computed-props/_config.js new file mode 100644 index 0000000000..87aac12083 --- /dev/null +++ b/test/runtime/samples/const-tag-each-destructure-computed-props/_config.js @@ -0,0 +1,15 @@ +export default { + html: ` + + + + `, + + async test({ component, target, assert }) { + component.boxes = [{ length: 10, width: 20, height: 30 }]; + + assert.htmlEqual(target.innerHTML, + '' + ); + } +}; diff --git a/test/runtime/samples/const-tag-each-destructure-computed-props/main.svelte b/test/runtime/samples/const-tag-each-destructure-computed-props/main.svelte new file mode 100644 index 0000000000..f45674044e --- /dev/null +++ b/test/runtime/samples/const-tag-each-destructure-computed-props/main.svelte @@ -0,0 +1,42 @@ + + +{#each boxes as { length, width, height }} + {@const { + [`two${dimension}`]: { + i = 1, + [`bottom${area}`]: bottom, + [`side${area}${i++}`]: sideone, + [`side${area}${i++}`]: sidetwo + }, + [`three${dimension}`]: { + volume + } + } = calculate(length, width, height)} + +{/each}