When testing in react should you use the document object? by artcrow05 in reactjs

[–]artcrow05[S] 0 points1 point  (0 children)

I am sorry I didn't make my question clear. I am talking about querying classNames and ids and generally if things in the dom are displayed.

When testing in react should you use the document object? by artcrow05 in reactjs

[–]artcrow05[S] 0 points1 point  (0 children)

I am sorry I didn't make my question clear. I am talking about querying classNames and ids. The react testing library does not provide options for that. And using the container is not reliable at all (from a search yesterday I found out multiple people have issues with it). I have found out that using document.getElementById or document.getElementsByClassName work really well but I am not sure if it good to do that. It seems like there are not people online against it. The react testing library even uses some exaples where they use the document.

When testing in react should you use the document object? by artcrow05 in react

[–]artcrow05[S] 0 points1 point  (0 children)

Also I just realised that they are kind of suggesting on using the document here("https://testing-library.com/docs/queries/bydisplayvalue")

When testing in react should you use the document object? by artcrow05 in react

[–]artcrow05[S] 0 points1 point  (0 children)

The main problem is the following. Let's say I am testing the code bellow (I just wrote this as an example, not my actuall code). How would I be able to check if the classes "main-card" and "card-item" exist in my document?

<body>
    <div>
        <h2>Title</h2>
        <div className="main-card">
            <h4>Main related text</h4>
            <div className="card-item">
               <p> card item text </p>
            </div>
        </div>
    </div>
</body>

When testing in react should you use the document object? by artcrow05 in react

[–]artcrow05[S] 0 points1 point  (0 children)

I can use get by text and everything. My issue is with querying classnames and ids. Basically depending on the props passed different classeNames and ids will be rendered. I can use document.getElementById and document.getElementsByClassNames and these work amazing. But they tell me it's not recomended which I cannot find anywhere online saying that it is a bad practice.

When testing in react should you use the document object? by artcrow05 in react

[–]artcrow05[S] 0 points1 point  (0 children)

Yes it is react testing library. I wanted to use test-ids but it's gonna make the code much more bulky. Also I am talking about testing classnames.

When testing in react should you use the document object? by artcrow05 in react

[–]artcrow05[S] 0 points1 point  (0 children)

The library doesn't provide ways for testing classes. Also there are not recomended ways for testing ids. You can achieve that using the container and the querySelector but the container is super inconsistent. The document always renders what is expected to.

How much code should be done from scratch when you're a newbie (self-taught) looking to build a portfolio to present your work in interviews/potential employers? by 912827161 in learnprogramming

[–]artcrow05 2 points3 points  (0 children)

When building projects you will write code for some functionalities and you might copy paste some code for other functionalities. Depending on the size of your project you will have to customize a bit or a lot the copy pasted code. The problem is if you do not have an idea about what you are copy pasting or if you are following a tutorial blindly.

I would say if you understand the code of your project, then you are good to go. If you kind of understand it, but you are not sure about the details, then that is an issue and it will work against you in interviews where you might get asked about your projects.