diff --git a/test/production.test.tsx b/test/production.test.tsx new file mode 100644 index 0000000..2421fe7 --- /dev/null +++ b/test/production.test.tsx @@ -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
Hello World
+ } + + const { getByText } = await vbr.render() + 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) +}) diff --git a/vitest.config.ts b/vitest.config.ts index 48c264e..670b610 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -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: {