import { component, html } from '../../src/fudgel.js'; component( 'custom-element', { template: html` `, }, class { internalValue = 'b'; buttonClicked(event: Event) { this.internalValue = `BBB`; } } ); component( 'test-true', { template: '', }, class { disabled = true; } ); component( 'test-false', { template: '', }, class { disabled = false; } ); component( 'the-child', { attr: ['test', 'childValue'], template: html`
{{test}}
{{childValue}}
`, }, class { test = 'value before init'; childValue = 'value before attr'; buttonClicked() { this.test = 'test-update'; this.childValue = 'child-value-update'; } } ); describe('attr', () => { it('replaces text in mustache-like syntax for attributes', () => { cy.mount(''); cy.get('#test').should('have.attr', 'class', 'a b c fudgel_custom-element'); cy.get('button').click(); cy.get('#test').should('have.attr', 'class', 'a BBB c fudgel_custom-element'); }); it('uses camelCase attributes', () => { cy.mount(''); cy.get('#test').should('have.text', 'TEST'); cy.get('#childValue').should('have.text', 'Ok'); cy.get('button').click(); cy.get('#test').should('have.text', 'test-update'); cy.get('#childValue').should('have.text', 'child-value-update'); cy.get('the-child').should('have.attr', 'test', 'test-update'); cy.get('the-child').should( 'have.attr', 'child-value', 'child-value-update' ); }); it('sets true as empty string for attributes', () => { cy.mount(''); cy.get('#test').should('have.attr', 'disabled'); }); it('removes attributes set as false', () => { cy.mount(''); cy.get('#test').should('not.have.attr', 'disabled'); }); });