Skip to content

fix: ensure fireEvent is exported #339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/__tests__/events.test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
import { fireEvent, render } from '@testing-library/svelte'
import { describe, expect, test } from 'vitest'

import { fireEvent, render } from '@testing-library/svelte'
import Comp from './fixtures/Comp.svelte'

describe('events', () => {
test('state changes are flushed after firing an event', async () => {
const { getByText } = render(Comp, { props: { name: 'World' } })
const button = getByText('Button')

await fireEvent.click(button)
const result = fireEvent.click(button)

await expect(result).resolves.toBe(true)
expect(button).toHaveTextContent('Button Clicked')
})

test('calling `fireEvent` directly works too', async () => {
const { getByText } = render(Comp, { props: { name: 'World' } })
const button = getByText('Button')

await fireEvent(
const result = fireEvent(
button,
new MouseEvent('click', {
bubbles: true,
cancelable: true
cancelable: true,
})
)

await expect(result).resolves.toBe(true)
expect(button).toHaveTextContent('Button Clicked')
})
})
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ if (typeof afterEach === 'function' && !process.env.STL_SKIP_AUTO_CLEANUP) {
})
}

export * from './pure.js'
// export all base queries, screen, etc.
export * from '@testing-library/dom'

// export svelte-specific functions and custom `fireEvent`
// `fireEvent` must be a named export to take priority over wildcard export above
export { act, cleanup, fireEvent, render } from './pure.js'
8 changes: 6 additions & 2 deletions src/svelte5-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ if (typeof afterEach === 'function' && !process.env.STL_SKIP_AUTO_CLEANUP) {
})
}

export { act, fireEvent } from './pure.js'
export * from './svelte5.js'
// export all base queries, screen, etc.
export * from '@testing-library/dom'

// export svelte-specific functions and custom `fireEvent`
// `fireEvent` must be a named export to take priority over wildcard export above
export { act, fireEvent } from './pure.js'
export { cleanup, render } from './svelte5.js'
3 changes: 2 additions & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'node:path'

import { svelte } from '@sveltejs/vite-plugin-svelte'
import path from 'path'
import { VERSION as SVELTE_VERSION } from 'svelte/compiler'
import { defineConfig } from 'vite'

Expand Down