Cannot access `variable` before initialization when using `screen.getByTestId()` in React Testing Library [closed] - reactjs

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed yesterday.
Improve this question
(PS: my question is solved but closed. So I updated this question to make it simpler, but still replicating the same problem as before)
I am very new to React and now I am learning how to test React Components with React Testing Library.
I have made an Education Component that would render education details. But for this question I will keep the Component very simple to replicate the error.
I want to test if Education is rendered correctly with toBeInTheDocument() but I came across a problem while using getByTestId() to select the Education Component as a whole. I got the Reference Error: Cannot access 'Education' before initialization error.
My Education.js Component:
class Education extends React.Component {
render() {
return (
<div data-testid='Education' id='Education'>
My Education
</div>
)
}
My Education.test.js:
import { render, screen } from '#testing-library/react'
import '#testing-library/jest-dom'
describe('Test Components are rendering correctly', () => {
it('renders Education Component', () => {
render(<Education />)
const Education = screen.getByTestId('Education')
expect(Education).toBeInTheDocument();
})
})
Error Screenshot:
Please let me know what I am doing wrong or should I provide more information to solve this problem. Thank you in advance, I appreciate it!

Related

Why am I unable to console.log() anything in react? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
import React from "react";
export default class App extends React.Component {
render() {
console.log('Hello');
return (
<div> App component </div>
)
}
}
I am facing this issue since yesterday. Hello should have been printed in the console on inspecting my website but nothing is getting displayed. I saved the code and also refreshed the browser.
Open your browser inspection and select the console tab on it. Click on the All levels and make sure all the options are selected:

How can I transfer Props from one component to another via Link [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
My Code
The code shows that when you enter data in three lines, they must be transmitted via Link using the State method, but when you try to display them on the secStr page, it gives Undefined
You have to add the withRouter HOC (high order component) into secStr page to have access to location props and the state data
Take a look at this:
https://reactrouter.com/web/api/withRouter
Something like this:
import React, {
Component
} from "react";
import {
withRouter
} from "react-router";
class secStr extends Component {
render() {
console.log(this.props);
return ( <
div >
date in inputs <
br / >
<
/div>
);
}
}
export default withRouter(secStr);

putting html tags in index.js for my react app shows error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I decided to learn reactjs and on very first step I got an error. It throws error in src/index.js whenever I use html tags. Hover message at error says,'eg: does'nt have corresponding closing tag'.
code below is what I did;
import React from 'react';
import ReactDOM from 'react-dom';
const element = < h1 > Hello World < /h1>;
ReactDOM.render(element, document.getElementById('root'));
//<h1> tag throws error '<h1> has no closing tag' even it is closed.
//note: every html tag gives error.
import React from 'react';
import ReactDOM from 'react-dom';
const element = <h1> Hello World </h1>;
ReactDOM.render(element, document.getElementById('root'));
You cannot have spaces in the HTML tags.

React open select file dialog using ref not working? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm trying to open file dialog using react useRef hook.
when browser executes fileInputRef.current.click() code snippet I'm getting below error in console
error: File chooser dialog can only be shown with a user activation
This works well:
const inputFileRef = useRef();
...
const handleBtnClick = () => {
inputFileRef.current.click();
}
...
<form>
<input type="file" ref={inputFileRef} />
<button onClick={handleBtnClick}>Select file</button>
</form>

TypeError:- Class extends value undefined is not a constructor or null [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
I have just started learning React. I am getting this error in localhost:3000 when I am running the server through node.js
TypeError: Class extends value undefined is not a constructor or null
Index.js
import React , {Compnonent} from "react";
class lottery extends Compnonent {
render() {
return (
<h1>Decentralized Lottery Application</h1>
)
}
}
export default lottery;
There is a typo {Component} fix it.
You spelled it as {Compnonent}
import React , {Component} from "react";

Resources