Skip to content
Closed
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
44 changes: 44 additions & 0 deletions test/production.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { expect, test, vi } from 'vitest'
import * as vbr from 'vitest-browser-react'
import { useEffect } from 'react'
import { useCounter } from './fixtures/useCounter'

test('vbr exposes correct methods', () => {
expect(vbr).toMatchInlineSnapshot(`
{
"cleanup": [Function],
"render": [Function],
"renderHook": [Function],
}
`)
})

test('vbr renders a component', async () => {
const cleanup = vi.fn()
function Example() {
useEffect(() => {
return () => {
cleanup()
}
})
return <div>Hello World</div>
}

const { getByText } = await vbr.render(<Example />)
expect(getByText('Hello World')).toBeInTheDocument()
expect(cleanup).not.toHaveBeenCalled()

await vbr.cleanup()

expect(cleanup).toHaveBeenCalled()
})

test('should increment counter', async () => {
const { result, act } = await vbr.renderHook(() => useCounter())

await act(() => {
result.current.increment()
})

expect(result.current.count).toBe(1)
})
4 changes: 4 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { playwright } from '@vitest/browser-playwright'

export default defineConfig({
plugins: [react()],
optimizeDeps: {
// needed for production test
include: ['vitest-browser-react'],
},
test: {
printConsoleTrace: true,
browser: {
Expand Down