From 0acd7903f019b059ff1ef946caa2f407279cb0dc Mon Sep 17 00:00:00 2001 From: Nguyen Tran Date: Mon, 13 Mar 2023 18:32:06 -0400 Subject: [PATCH] Add computed property destructuring tests for each blocks --- .../_config.js | 24 +++++++++++++++++ .../main.svelte | 7 +++++ .../_config.js | 26 +++++++++++++++++++ .../main.svelte | 12 +++++++++ 4 files changed, 69 insertions(+) create mode 100644 test/runtime/samples/each-block-destructured-array-computed-props/_config.js create mode 100644 test/runtime/samples/each-block-destructured-array-computed-props/main.svelte create mode 100644 test/runtime/samples/each-block-destructured-object-computed-props/_config.js create mode 100644 test/runtime/samples/each-block-destructured-object-computed-props/main.svelte diff --git a/test/runtime/samples/each-block-destructured-array-computed-props/_config.js b/test/runtime/samples/each-block-destructured-array-computed-props/_config.js new file mode 100644 index 0000000000..bc5fe12539 --- /dev/null +++ b/test/runtime/samples/each-block-destructured-array-computed-props/_config.js @@ -0,0 +1,24 @@ +export default { + props: { + array: [ + [1, 2, 3, 4, 5], + [6, 7, 8], + [9, 10, 11, 12], + [13, 14, 15, 16, 17, 18, 19, 20, 21, 22] + ] + }, + + html: ` +

First: 1, Half: 3, Last: 5, Length: 5

+

First: 6, Half: 7, Last: 8, Length: 3

+

First: 9, Half: 11, Last: 12, Length: 4

+

First: 13, Half: 18, Last: 22, Length: 10

+ `, + + test({ assert, component, target }) { + component.array = [[23, 24, 25, 26, 27, 28, 29]]; + assert.htmlEqual( target.innerHTML, ` +

First: 23, Half: 26, Last: 29, Length: 7

+ `); + } +}; diff --git a/test/runtime/samples/each-block-destructured-array-computed-props/main.svelte b/test/runtime/samples/each-block-destructured-array-computed-props/main.svelte new file mode 100644 index 0000000000..00a9a99a89 --- /dev/null +++ b/test/runtime/samples/each-block-destructured-array-computed-props/main.svelte @@ -0,0 +1,7 @@ + + +{#each array as { 0: first, length, [length - 1]: last, [Math.floor(length / 2)]: half }} +

First: {first}, Half: {half}, Last: {last}, Length: {length}

+{/each} diff --git a/test/runtime/samples/each-block-destructured-object-computed-props/_config.js b/test/runtime/samples/each-block-destructured-object-computed-props/_config.js new file mode 100644 index 0000000000..7bd1a7edbe --- /dev/null +++ b/test/runtime/samples/each-block-destructured-object-computed-props/_config.js @@ -0,0 +1,26 @@ +export default { + props: { + firstString: 'cats', + secondString: 'dogs', + objectsArray: [ + { dogs: 'woof', cats: 'meow', stac: 'stack', DOGS: 'WOOF' }, + { dogs: 'A German sheppard', cats: 'A tailless cat', stac: 'A jenga tower', DOGS: 'A GERMAN SHEPPARD' }, + { dogs: 'dogs', cats: 'cats', stac: 'stac', DOGS: 'DOGS' } + ] + }, + + html: ` +

cats: meow

+

dogs: woof

+

stac: stack

+

DOGS: WOOF

+

cats: A tailless cat

+

dogs: A German sheppard

+

stac: A jenga tower

+

DOGS: A GERMAN SHEPPARD

+

cats: cats

+

dogs: dogs

+

stac: stac

+

DOGS: DOGS

+ ` +}; diff --git a/test/runtime/samples/each-block-destructured-object-computed-props/main.svelte b/test/runtime/samples/each-block-destructured-object-computed-props/main.svelte new file mode 100644 index 0000000000..a99fe6401f --- /dev/null +++ b/test/runtime/samples/each-block-destructured-object-computed-props/main.svelte @@ -0,0 +1,12 @@ + + +{#each objectsArray as { [firstString]: firstProp, [secondString]: secondProp, [firstString.split('').reverse().join('')]: reverseFirst, [secondString.toUpperCase()]: upperSecond } } +

{firstString}: {firstProp}

+

{secondString}: {secondProp}

+

{firstString.split('').reverse().join('')}: {reverseFirst}

+

{secondString.toUpperCase()}: {upperSecond}

+{/each}