I generated a project using create-react-app with the --typescript option.
This is my app:
import React from 'react';
const App: React.FC = () => {
return (
<div className="App">
<div>
<h1 id="pageHeader">Home page</h1>
<p>This is the Home page</p>
</div>
</div>
);
};
export default App;
My current test is:
import React from 'react';
import ReactDOM from 'react-dom';
import {render} from '@testing-library/react';
import "@testing-library/jest-dom/extend-expect";
import App from './App';
test('Verify page header', () => {
const {getByText} = render(<App/>);
expect(getByText('Home page')).toBeInTheDocument;
});
The question: I want to test a little more. Besides testing if "Home page" occurs anywhere in my page, I want to make sure that the text "Home Page" is located in the h1 element. How do I get the full element (preferably via getElementById) from the react-testing-library so I can do assertions on it with Jest?