2d854092a4
* Serialize boolean attributes without a value Fixes #307 * Update the attrs test * Adds a changeset * Adds test that components receive booleans
39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
import { suite } from 'uvu';
|
|
import * as assert from 'uvu/assert';
|
|
import { doc } from './test-utils.js';
|
|
import { setup } from './helpers.js';
|
|
|
|
const Attributes = suite('Attributes test');
|
|
|
|
setup(Attributes, './fixtures/astro-attrs');
|
|
|
|
Attributes('Passes attributes to elements as expected', async ({ runtime }) => {
|
|
const result = await runtime.load('/');
|
|
if (result.error) throw new Error(result.error);
|
|
|
|
const $ = doc(result.contents);
|
|
|
|
const ids = ['false-str', 'true-str', 'false', 'true', 'empty', 'null', 'undefined'];
|
|
const specs = ['false', 'true', undefined, '', '', undefined, undefined];
|
|
|
|
let i = 0;
|
|
for (const id of ids) {
|
|
const spec = specs[i];
|
|
const attr = $(`#${id}`).attr('attr');
|
|
assert.equal(attr, spec, `Passes ${id} as "${spec}"`);
|
|
i++;
|
|
}
|
|
});
|
|
|
|
Attributes('Passes boolean attributes to components as expected', async ({ runtime }) => {
|
|
const result = await runtime.load('/component');
|
|
if (result.error) throw new Error(result.error);
|
|
|
|
const $ = doc(result.contents);
|
|
assert.equal($('#true').attr('attr'), 'attr-true');
|
|
assert.equal($('#true').attr('type'), 'boolean');
|
|
assert.equal($('#false').attr('attr'), 'attr-false');
|
|
assert.equal($('#false').attr('type'), 'boolean');
|
|
});
|
|
|
|
Attributes.run();
|