summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Tony Sullivan <tony.f.sullivan@outlook.com> 2022-02-07 20:14:26 +0000
committerGravatar GitHub <noreply@github.com> 2022-02-07 15:14:26 -0500
commit41b659b12ece2c800ea9cc23a1c93ff549559a32 (patch)
tree081eb1a2e84949bb0357cf72dba7b851460cbd45
parent73bf4d8bb8e0d4f715e5965664f457b84549f97c (diff)
downloadastro-41b659b12ece2c800ea9cc23a1c93ff549559a32.tar.gz
astro-41b659b12ece2c800ea9cc23a1c93ff549559a32.tar.zst
astro-41b659b12ece2c800ea9cc23a1c93ff549559a32.zip
adding test coverage for boolean and enum HTML attributes (#2544)
-rw-r--r--packages/astro/test/astro-attrs.test.js27
-rw-r--r--packages/astro/test/fixtures/astro-attrs/src/pages/index.astro15
2 files changed, 31 insertions, 11 deletions
diff --git a/packages/astro/test/astro-attrs.test.js b/packages/astro/test/astro-attrs.test.js
index 173c1e2ec..bf0106af7 100644
--- a/packages/astro/test/astro-attrs.test.js
+++ b/packages/astro/test/astro-attrs.test.js
@@ -15,18 +15,25 @@ describe('Attributes', async () => {
const $ = cheerio.load(html);
const attrs = {
- 'false-str': 'false',
- 'true-str': 'true',
- false: undefined,
- true: 'true',
- empty: '',
- null: undefined,
- undefined: undefined,
+ 'false-str': { attribute: 'attr', value: 'false' },
+ 'true-str': { attribute: 'attr', value: 'true' },
+ false: { attribute: 'attr', value: undefined },
+ true: { attribute: 'attr', value: 'true' },
+ empty: { attribute: 'attr', value: '' },
+ null: { attribute: 'attr', value: undefined },
+ undefined: { attribute: 'attr', value: undefined },
+ 'html-boolean': { attribute: 'async', value: 'async' },
+ 'html-boolean-true': { attribute: 'async', value: 'async' },
+ 'html-boolean-false': { attribute: 'async', value: undefined },
+ 'html-enum': { attribute: 'draggable', value: 'true' },
+ 'html-enum-true': { attribute: 'draggable', value: 'true' },
+ 'html-enum-false': { attribute: 'draggable', value: 'false' },
};
- for (const [k, v] of Object.entries(attrs)) {
- const attr = $(`#${k}`).attr('attr');
- expect(attr).to.equal(v);
+ for (const id of Object.keys(attrs)) {
+ const { attribute, value } = attrs[id]
+ const attr = $(`#${id}`).attr(attribute);
+ expect(attr).to.equal(value);
}
});
diff --git a/packages/astro/test/fixtures/astro-attrs/src/pages/index.astro b/packages/astro/test/fixtures/astro-attrs/src/pages/index.astro
index 40f1a1f0a..82e03a3ae 100644
--- a/packages/astro/test/fixtures/astro-attrs/src/pages/index.astro
+++ b/packages/astro/test/fixtures/astro-attrs/src/pages/index.astro
@@ -5,4 +5,17 @@
<span id="empty" attr="" />
<span id="null" attr={null} />
<span id="undefined" attr={undefined} />
-
+<!--
+ Per HTML spec, some attributes should be treated as booleans
+ These should always render <span async /> or <span /> (without a string value)
+-->
+<span id='html-boolean' async />
+<span id='html-boolean-true' async={true} />
+<span id='html-boolean-false' async={false} />
+<!--
+ Other attributes should be treated as string enums
+ These should always render <span draggable="true" /> or <span draggable="false" />
+-->
+<span id='html-enum' draggable='true' />
+<span id='html-enum-true' draggable={true} />
+<span id='html-enum-false' draggable={false} /> \ No newline at end of file