Skip to content

Commit

Permalink
fix(ld-card): throws if there is no parent element
Browse files Browse the repository at this point in the history
  • Loading branch information
borisdiakur committed Jun 1, 2023
1 parent ef35bbe commit dbee889
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/liquid/components/ld-card/ld-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class LdCard {
@Prop() size?: 'sm'

componentWillLoad() {
if (this.el.parentElement.tagName === 'LD-CARD-STACK') {
if (this.el.parentElement?.tagName === 'LD-CARD-STACK') {
this.el.setAttribute('role', 'listitem')
}
}
Expand Down
36 changes: 36 additions & 0 deletions src/liquid/components/ld-card/test/ld-card.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { newSpecPage } from '@stencil/core/testing'
import { LdCard } from '../ld-card'
import { h } from '@stencil/core'

describe('ld-card', () => {
it('renders', async () => {
Expand Down Expand Up @@ -35,4 +36,39 @@ describe('ld-card', () => {
expect(page.root).toHaveClass('ld-card--interactive-sticky')
})
})

describe('as listitem', () => {
it('adds listitem role if in card stack', async () => {
const page = await newSpecPage({
components: [LdCard],
template: () => (
<ld-card-stack>
<ld-card>Card A</ld-card>
</ld-card-stack>
),
})
expect(page.body.querySelector('ld-card').getAttribute('role')).toEqual(
'listitem'
)
})

it('does not add listitem role if not in card stack', async () => {
const page = await newSpecPage({
components: [LdCard],
template: () => (
<div>
<ld-card>Card A</ld-card>
</div>
),
})
expect(
page.body.querySelector('ld-card').getAttribute('role')
).not.toEqual('listitem')
})

it('does not throw if there is no parent element', async () => {
const component = new LdCard()
component.componentWillLoad()
})
})
})

1 comment on commit dbee889

@vercel
Copy link

@vercel vercel bot commented on dbee889 Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

liquid – ./

liquid-git-main-uxsd.vercel.app
liquid-uxsd.vercel.app
liquid-oxygen.vercel.app

Please sign in to comment.