`);
});
it('updates the internal input when the prop value changes between distinct falsy states', async () => {
@Component({ tag: 'cmp-input-wrapper' })
class CmpA {
@Prop() value: any;
render() {
return ;
}
}
const { root, waitForChanges } = await newSpecPage({
components: [CmpA],
html: ``,
});
root.value = 0;
await waitForChanges();
expect(root.querySelector('#internal-input').value).toBe('0');
root.value = '';
await waitForChanges();
expect(root.querySelector('#internal-input').value).toBe('');
root.value = 0;
await waitForChanges();
expect(root.querySelector('#internal-input').value).toBe('0');
});
it('should maintain reactivity when prop is set to undefined on element before initialization', async () => {
@Component({ tag: 'cmp-lazy-prop' })
class CmpLazyProp {
@Prop() first?: string;
render() {
return
{this.first ?? 'empty'}
;
}
}
// Create page without flushing queue - element exists but component not yet initialized
const page = await newSpecPage({
components: [CmpLazyProp],
html: ``,
flushQueue: false,
});
// Set property to undefined on element BEFORE component initializes
// This creates an "own property" that shadows the getter/setter
(page.body.querySelector('cmp-lazy-prop') as any).first = undefined;
// Now initialize the component
await page.waitForChanges();
const root = page.root;
expect(root).toEqualHtml(`
empty
`);
// Update the prop - this should work because lazy property handling
// correctly cleaned up the shadowing own property
root.first = 'updated';
await page.waitForChanges();
expect(root).toEqualHtml(`
updated
`);
expect(root.first).toBe('updated');
});
it('should maintain reactivity when prop is set to null on element before initialization', async () => {
@Component({ tag: 'cmp-lazy-prop-null' })
class CmpLazyPropNull {
@Prop() value?: string;
render() {
return
{this.value ?? 'empty'}
;
}
}
const page = await newSpecPage({
components: [CmpLazyPropNull],
html: ``,
flushQueue: false,
});
(page.body.querySelector('cmp-lazy-prop-null') as any).value = null;
await page.waitForChanges();
const root = page.root;
// null is a valid value, should render 'empty' due to nullish coalescing
expect(root).toEqualHtml(`