Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cschroeter committed Nov 28, 2024
1 parent 67dbf22 commit 4c058af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 37 deletions.
13 changes: 10 additions & 3 deletions packages/svelte/src/lib/components/factory/examples/basic.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<script lang="ts">
import Ark from '../factory.svelte'
import Ark from '../factory.svelte'
interface Props {
onClickParent?: () => void
onClickChild?: () => void
}
const { onClickParent, onClickChild }: Props = $props()
</script>

<Ark
Expand All @@ -9,12 +15,13 @@
data-testid="parent"
data-part="parent"
class="parent"
style="background: red;"
style="background: red"
onclick={onClickParent}
>
{#snippet render(props)}
<Ark
as="span"
{...props({ id: 'child', class: 'child', style: 'color: blue' })}
{...props({ id: 'child', class: 'child', style: 'color: blue', onclick: onClickChild })}
data-testid="child"
data-part="child"
>
Expand Down
44 changes: 10 additions & 34 deletions packages/svelte/src/lib/components/factory/factory.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { render, screen } from '@testing-library/svelte'
import { describe, expect, it } from 'vitest'
import user from '@testing-library/user-event'
import { describe, expect, it, vi } from 'vitest'
import ComponentUnderTest from './examples/basic.svelte'

describe('Ark Factory', () => {
Expand Down Expand Up @@ -27,38 +28,13 @@ describe('Ark Factory', () => {
expect(screen.getByText('Ark UI')).toBeVisible()
})

// it('should merge events', async () => {
// const onClickParent = vi.fn()
// const onClickChild = vi.fn()
// render(
// <ark.div data-testid="parent" onClick={onClickParent} asChild>
// <ark.span data-testid="child" onClick={onClickChild} />
// </ark.div>,
// )
// await user.click(screen.getByTestId('child'))
// expect(onClickParent).toHaveBeenCalled()
// expect(onClickChild).toHaveBeenCalled()
// })
it('should merge events', async () => {
const onClickParent = vi.fn()
const onClickChild = vi.fn()
render(ComponentUnderTest, { onClickParent, onClickChild })
await user.click(screen.getByTestId('child'))

// it('should propagate asChild', async () => {
// render(
// <ark.div data-testid="parent" asChild>
// <ark.span asChild>
// <ark.span>Ark UI</ark.span>
// </ark.span>
// </ark.div>,
// )
// expect(screen.getByText('Ark UI')).toHaveAttribute('data-testid', 'parent')
// })

// it('should stop propagate asChild', async () => {
// render(
// <ark.div data-testid="parent" asChild>
// <ark.span asChild={false}>
// <ark.span>Ark UI</ark.span>
// </ark.span>
// </ark.div>,
// )
// expect(screen.getByText('Ark UI')).not.toHaveAttribute('data-testid', 'parent')
// })
expect(onClickParent).toHaveBeenCalled()
expect(onClickChild).toHaveBeenCalled()
})
})

0 comments on commit 4c058af

Please sign in to comment.