From 9626fdef58f1e2cd5d3a77d94194d01b3d7c1d81 Mon Sep 17 00:00:00 2001 From: Horacio Herrera Date: Sat, 15 Jan 2022 03:59:11 +0100 Subject: [PATCH] test: update RTL example (#530) Co-authored-by: Anthony Fu --- examples/react-testing-lib/src/App.test.tsx | 8 ++++---- examples/react-testing-lib/src/test/setup.ts | 1 + examples/react-testing-lib/vite.config.ts | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 examples/react-testing-lib/src/test/setup.ts diff --git a/examples/react-testing-lib/src/App.test.tsx b/examples/react-testing-lib/src/App.test.tsx index e58778ff2..2a004f6eb 100644 --- a/examples/react-testing-lib/src/App.test.tsx +++ b/examples/react-testing-lib/src/App.test.tsx @@ -1,16 +1,16 @@ import { describe, expect, it } from 'vitest' -import { render, screen, userEvent } from './utils/test-utils' import App from './App' +import { render, screen, userEvent } from './utils/test-utils' describe('Simple working test', () => { it('the title is visible', () => { render() - expect(screen.getByText(/Hello Vite \+ React!/i)).toBeDefined() + expect(screen.getByText(/Hello Vite \+ React!/i)).toBeInTheDocument() }) - it('should increment count on click', () => { + it('should increment count on click', async() => { render() userEvent.click(screen.getByRole('button')) - expect(screen.findByText(/count is: 1/i)).toBeDefined() + expect(await screen.findByText(/count is: 1/i)).toBeInTheDocument() }) }) diff --git a/examples/react-testing-lib/src/test/setup.ts b/examples/react-testing-lib/src/test/setup.ts new file mode 100644 index 000000000..c44951a68 --- /dev/null +++ b/examples/react-testing-lib/src/test/setup.ts @@ -0,0 +1 @@ +import '@testing-library/jest-dom' diff --git a/examples/react-testing-lib/vite.config.ts b/examples/react-testing-lib/vite.config.ts index 3f4d16755..c954c14c4 100644 --- a/examples/react-testing-lib/vite.config.ts +++ b/examples/react-testing-lib/vite.config.ts @@ -10,5 +10,6 @@ export default defineConfig({ test: { global: true, environment: 'jsdom', + setupFiles: './src/test/setup.ts', }, }) -- 2.51.2