import { beHidden, beVisible, haveText, beChecked, haveAttribute, haveClasses, haveValue, notBeChecked, notHaveAttribute, notHaveClasses, test, html } from '../../utils'
test('sets attribute bindings on initialize',
html`
[Subject]
`,
({ get }) => get('span').should(haveAttribute('foo', 'bar'))
)
test('sets undefined nested keys to empty string',
html`
`,
({ get }) => get('span').should(haveAttribute('foo', ''))
)
test('style attribute bindings are added by string syntax',
html`
`,
({ get }) => get('span').should(haveClasses(['foo']))
)
test('aria-pressed/checked attribute boolean values are cast to a true/false string',
html`
`,
({ get }) => get('span').should(haveAttribute('aria-pressed', 'true'))
)
test('non-boolean attributes set to null/undefined/false are removed from the element',
html`
`,
({ get }) => {
get('a:nth-child(1)').should(notHaveAttribute('href'))
get('a:nth-child(2)').should(notHaveAttribute('href'))
get('a:nth-child(3)').should(notHaveAttribute('href'))
get('span:nth-child(1)').should(notHaveAttribute('visible'))
get('span:nth-child(2)').should(notHaveAttribute('visible'))
get('span:nth-child(3)').should(notHaveAttribute('visible'))
}
)
test('non-boolean empty string attributes are not removed',
html`
`,
({ get }) => get('a').should(haveAttribute('href', ''))
)
test('boolean attribute values are set to their attribute name if true and removed if false',
html`
`,
({ get }) => {
get('span').should(beVisible())
get('button').click()
get('span').should(beVisible())
get('span').should(beHidden())
}
)
test('x-bind object syntax event handlers defined as functions receive the event object as their first argument',
html`
foo
`,
({ get }) => {
get('span').should(haveText('foo'))
get('button').click()
get('span').should(haveText('bar'))
}
)
test('x-bind object syntax event handlers defined as functions receive the event object as their first argument',
html`
foo
`,
({ get }) => {
get('span').should(haveText('foo'))
get('button').click()
get('span').should(haveText('bar'))
}
)
test('Can retrieve Alpine bound data with global bound method',
html`
`,
({ get }) => {
get('#1').should(haveText('bar'))
get('#2').should(haveText('bar'))
get('#3').should(haveText('true'))
get('#4').should(haveText(''))
get('#5').should(haveText('bar'))
}
)