Skip to content
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

test(transitions): add on:introend test #311

Merged
merged 1 commit into from
Feb 5, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^2.4.2",
"@testing-library/jest-dom": "^6.3.0",
"@testing-library/user-event": "^14.5.2",
"@typescript-eslint/eslint-plugin": "6.19.1",
"@typescript-eslint/parser": "6.19.1",
"@vitest/coverage-v8": "^0.33.0",
Expand Down
18 changes: 18 additions & 0 deletions src/__tests__/fixtures/Transitioner.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script>
import { blur } from 'svelte/transition'

let show = false
let introDone = false
</script>

<button on:click={() => (show = true)}>Show</button>

{#if show}
<div in:blur={{ duration: 64 }} on:introend={() => (introDone = true)}>
{#if introDone}
<p data-testid="intro-done">Done</p>
{:else}
<p data-testid="intro-pending">Pending</p>
{/if}
</div>
{/if}
30 changes: 30 additions & 0 deletions src/__tests__/transition.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { userEvent } from '@testing-library/user-event'
import { beforeEach, describe, expect, test, vi } from 'vitest'

import { render, screen, waitFor } from '..'
import Transitioner from './fixtures/Transitioner.svelte'

describe('transitions', () => {
beforeEach(() => {
if (window.navigator.userAgent.includes('jsdom')) {
const raf = (fn) => setTimeout(() => fn(new Date()), 16)
vi.stubGlobal('requestAnimationFrame', raf)
}
})

test('on:introend', async () => {
const user = userEvent.setup()

render(Transitioner)
const start = screen.getByRole('button')
await user.click(start)

const pending = screen.getByTestId('intro-pending')
expect(pending).toBeInTheDocument()

await waitFor(() => {
const done = screen.queryByTestId('intro-done')
expect(done).toBeInTheDocument()
})
})
})