From e955f3fc4fd5ba627b9cb6aede7855e33862c73a Mon Sep 17 00:00:00 2001 From: Philippe Torrel Date: Thu, 29 Oct 2026 15:15:34 +0100 Subject: [PATCH] --- .../__test__/ExampleComponent.test.jsx | 21 ++++++++++++++++++- .../src/test/ExampleComponent.test.jsx | 21 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 06_react/unterricht/tag39/02_react-app-with-tests/src/test/ExampleComponent.test.jsx diff --git a/06_react/unterricht/tag39/02_react-app-with-tests/src/components/__test__/ExampleComponent.test.jsx b/06_react/unterricht/tag39/02_react-app-with-tests/src/components/__test__/ExampleComponent.test.jsx index 13ce2bd..dc05c52 100644 --- a/06_react/unterricht/tag39/02_react-app-with-tests/src/components/__test__/ExampleComponent.test.jsx +++ b/06_react/unterricht/tag39/02_react-app-with-tests/src/components/__test__/ExampleComponent.test.jsx @@ -1,2 +1,21 @@ +import { render, screen } from '@testing-library/react'; +import ExampleComponent from '../ExampleComponent'; + +// import nicht notwendig ( Findet automatisch durch globale Setting statt) +import { test, it, expect } from 'vitest'; + // Test case -test('Component renders correctly and contains text "Hello World"'); +// it('should render correctly and contains text "Hello World"', () => {}) +test('Component renders correctly and contains text "Hello World"', () => { + // AAA - Arrange, Act, Assert + + // Arrange + render(); + + const element = screen.getByText(/Hello World/i); + + // Act - Assert + expect(element).toBeInTheDocument(); +}); + +// console.log(document.querySelector('p').textContent.includes('Hello World')); // => true diff --git a/06_react/unterricht/tag39/02_react-app-with-tests/src/test/ExampleComponent.test.jsx b/06_react/unterricht/tag39/02_react-app-with-tests/src/test/ExampleComponent.test.jsx new file mode 100644 index 0000000..133a441 --- /dev/null +++ b/06_react/unterricht/tag39/02_react-app-with-tests/src/test/ExampleComponent.test.jsx @@ -0,0 +1,21 @@ +import { render, screen } from '@testing-library/react'; +import ExampleComponent from '../components/ExampleComponent'; + +// import nicht notwendig ( Findet automatisch durch globale Setting statt) +import { test, it, expect } from 'vitest'; + +// Test case +// it('should render correctly and contains text "Hello World"', () => {}) +test('Component renders correctly and contains text "Hello World"', () => { + // AAA - Arrange, Act, Assert + + // Arrange + render(); + + const element = screen.getByText(/Hello World/i); + + // Act - Assert + expect(element).toBeInTheDocument(); +}); + +// console.log(document.querySelector('p').textContent.includes('Hello World')); // => true