import { component } from '../../src/fudgel.js'; // Make a simple string for easy testing function str(value: any): string { if (value === undefined) { return 'undefined'; } return JSON.stringify(value); } // Three components to show how attributes and properties come into a child. component('show-value-attr', { attr: ['value'], template: '{{str(value)}}', }, class ChildElement { str = str; value: any = 'initial'; }); component('show-value-prop', { prop: ['value'], template: '{{str(value)}}', }, class ChildElement { str = str; value: any = 'initial'; }); component('show-value-attr-prop', { attr: ['value'], prop: ['value'], template: '{{str(value)}}', }, class ChildElement { str = str; value: any = 'initial'; }); // Different ways that parents can interact with the child elements component('parent-element', { template: `

` }); component('parent-element-attr', { template: `

` }); component('parent-element-attr-interpolated', { template: `

` }, class { value = 'ok' }); component('parent-element-prop', { template: `

` }, class { value = 'ok' }); component('parent-element-attr-prop-interpolated', { template: `

` }, class { one = '1'; two = '2' }); describe('prop vs attr', () => { it('works with no incoming values', () => { cy.mount(''); cy.get('show-value-attr').should('have.text', 'null'); cy.get('show-value-prop').should('have.text', '"initial"'); cy.get('show-value-attr-prop').should('have.text', 'null'); }); it('works with attr', () => { cy.mount(''); cy.get('show-value-attr').should('have.text', '"ok"'); cy.get('show-value-prop').should('have.text', '"initial"'); cy.get('show-value-attr-prop').should('have.text', '"ok"'); }); it('works with attr (interpolated)', () => { cy.mount(''); cy.get('show-value-attr').should('have.text', '"ok"'); cy.get('show-value-prop').should('have.text', '"initial"'); cy.get('show-value-attr-prop').should('have.text', '"ok"'); }); it('works with prop', () => { cy.mount(''); cy.get('show-value-attr').should('have.text', 'null'); cy.get('show-value-prop').should('have.text', '"ok"'); cy.get('show-value-attr-prop').should('have.text', '"ok"'); }); it('works with attr and prop (interpolated)', () => { cy.mount(''); cy.get('show-value-attr').should('have.text', '"1"'); cy.get('show-value-prop').should('have.text', '"2"'); cy.get('show-value-attr-prop').should('have.text', '"2"'); }); });