Why do I get React Testing Library errors after adding a new test file?

I successfully created 8 tests, all on the same file, for one of my projects. They all run, they all pass.

However, I just added a new test file to test a separate component.

I must be missing something.
I am aware of the cleanup() function, but I am NOT using it due to this article by Kent C. Dodds himself who says the cleanup is now automatic. Article here.

Error is:

console.error
  Warning: Invalid DOM property `inputmode`. Did you mean `inputMode`?
      at input
at CcLogic (...creditCardLogic.js:25:34)

Why would a test work until a new file is created?

The test it is complaining about is:

test('mastercard logo displays if typing 25', async () => {
        const { container } = render(<CcLogic fieldId={"cc-field"} />)
        const input = screen.getByPlaceholderText('Ex: 4502783790218767')
        fireEvent.change(input, {target: {value: '25'}})
        const svgIcon = container.querySelector('.fa-cc-mastercard')
        expect(svgIcon).toBeInTheDocument()
    })

take value from another input without refreshing page in php

i have this fetch.php file

 $out='';
 while($row = mysqli_fetch_assoc($result)) {
 $out .=  '<option value='.$row["jam_mulai"].'>' .$row["jam_mulai"]. '-.$row["jam_berakhir"].'</option>'; 
} 
 echo $out;

and i want to take the data from the option value to another select option in different file.
to this input.php file

 <select class="form-control select2" name="nama_dokter" style="width: 100%;" id="nama_dokter">
                        <option value="" selected="true" disabled="disabled">Pilih Dokter</option>
                    <?php
                         $query  = mysqli_query($koneksi, "SELECT * FROM jadwal_praktek LEFT JOIN dokter
                                  ON jadwal_praktek.dokter_id=dokter.id WHERE status='Aktif' GROUP BY dokter_id");
                        while ($data = mysqli_fetch_array($query)){
                    ?>  

                       <option value="<?= $data['id_jadwal'];?>"><?php echo $data['nama_dkt'];?></option>
                    <?php } ?>
                    </select>

so i want that if jam_mulai that user choose is same with the jam_mulai and dokter_id that are already in the database, so the value of option value (input.php) will be inserted as the jadwal_id.

i have doctors (dokter_id) that have one or more than one schedule (jadwal_id) with different time (jam_mulai)

here’s the schedule table

i know its really confusing, i also find it confusing to explain, but that what i meant. if someone may know the solution, please reply. thanks in advance.

React js Item count after fetch returning strange response

I am trying to get data from server in react. Data fetching is ok and returning data as expected. There are duplicate items in the data. I want to get number of similar items as count. I have got a routine from internet it is saving data correctly in a array. But when I am trying to get only the count element of the object. In console log it is showing only an opening bracket. Why?

fetch("http://localhost:55663")
        .then((response) => response.json())
        .then((data) => {
          setItems(data);     

      const countsByCs = {};
          data.forEach(({ ItemId }) => {
            countsByCs[ItemId] = (countsByCs[ItemId] || 0) + 1;
          });
          const finalArray = Object.entries(countsByItem)
          .map(([ItemId, count]) => ({ ItemId, count }))
          .sort((a, b) => b.count - a.count);
          setItemCount(JSON.stringify(finalArray));


    console.log(items[0])



result= [

Why does javascript scoping not work as expected?

I’m new to node.js I’ve been coding some node.js based application, and met a behavior that I can’t understand. Bellow is and example code, in the main function, it initializes the class then uses it to map into another object. When I declare this mapper’s value to an arrow function, it successfully catches the local variable main. But when I don’t declare the value as an arrow function, it throws an error like this.

 this.env.url + "/messages",
               ^

TypeError: Cannot read properties of undefined (reading 'url')

I come from a python basis, and in python, the latter would work well enough since functions are a first class citizen.

Why does the scoping work only when I use the arrow function? Does it have to do with the specifics of how node.js deals with binding and closures?

class ExternalAPIClient {
  constructor() {
    let appKey = "some-key"

    this.env = {
      "url": `some-url`,
      "secretKey": "some-secret-key",
    }

  }

  querySenderProfileCategory() {
    return axios.get(
      this.env.url + "/sender/categories",
      {
        headers: {
          "Content-Type": "application/json;charset=UTF-8",
          "X-Secret-Key": this.env.secretKey,
        }
      }
    )
  }

  queryMessageList() {
    return axios.get(
      this.env.url + "/messages",
      {
        headers: {
          "Content-Type": "application/json;charset=UTF-8",
          "X-Secret-Key": this.env.secretKey,
        }
      }
    )
  }
}

const main = async () => {
  let client = new NHNCloudClient();

  const commands = {
    "querySenderProfileCategory": () => client.querySenderProfileCategory,
    "queryMessageList": client.queryMessageList,
  }

  const res = await client.querySenderProfileCategory(); // this works
  const res = await commands.queryMessageList(); // this throws error


  printObject(res.data)
};



main()

I need element to always first appear scrolled down

I need the element that holds the messages of my chat app to show the latest messages when you open a new chat, I have tried different things with javascript but nothing seems to work

<div class="conversation" id="conversation-2">
                    <div class="conversation-top">
                        <button type="button" class="conversation-back"><i class="ri-arrow-left-line"></i></button>
                        <div class="conversation-user">
                            <img class="conversation-user-image"
                                src="https://images.unsplash.com/photo-1534528741775-53994a69daeb?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8OXx8cGVvcGxlfGVufDB8fDB8fHww&auto=format&fit=crop&w=500&q=60"
                                alt="">
                            <div>
                                <div class="conversation-user-name">Someone 1</div>
                                <div class="conversation-user-status online">online</div>
                            </div>
                        </div>
                    </div>
                    <div class="conversation-main">
                        <ul class="conversation-wrapper">
                            <li class="conversation-item me">
                                <div class="conversation-item-side">
                                    <img class="conversation-item-image"
                                        src="https://images.unsplash.com/photo-1534528741775-53994a69daeb?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8OXx8cGVvcGxlfGVufDB8fDB8fHww&auto=format&fit=crop&w=500&q=60"
                                        alt="">
                                </div>
                                <div class="conversation-item-content">
                                    <div class="conversation-item-wrapper">
                                        <div class="conversation-item-box">
                                            <div class="conversation-item-text">
                                                <p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Amet natus
                                                    repudiandae quisquam sequi nobis suscipit consequatur rerum alias
                                                    odio repellat!</p>
                                                <div class="conversation-item-time">12:30</div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="conversation-item-wrapper">
                                        <div class="conversation-item-box">
                                            <div class="conversation-item-text">
                                                <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eaque,
                                                    tenetur!</p>
                                                <div class="conversation-item-time">12:30</div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </li>
                            <li class="conversation-item">
                                <div class="conversation-item-side">
                                    <img class="conversation-item-image"
                                        src="https://images.unsplash.com/photo-1534528741775-53994a69daeb?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8OXx8cGVvcGxlfGVufDB8fDB8fHww&auto=format&fit=crop&w=500&q=60"
                                        alt="">
                                </div>
                                <div class="conversation-item-content">
                                    <div class="conversation-item-wrapper">
                                        <div class="conversation-item-box">
                                            <div class="conversation-item-text">
                                                <p>Lorem, ipsum dolor sit amet consectetur adipisicing elit.</p>
                                                <div class="conversation-item-time">12:30</div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="conversation-item-wrapper">
                                        <div class="conversation-item-box">
                                            <div class="conversation-item-text">
                                                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque eos
                                                    ab in?</p>
                                                <div class="conversation-item-time">12:30</div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="conversation-item-wrapper">
                                        <div class="conversation-item-box">
                                            <div class="conversation-item-text">
                                                <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Sint,
                                                    debitis. Iste natus est aliquam ipsum doloremque fugiat, quidem eos
                                                    autem? Dolor quisquam laboriosam enim cum laborum suscipit
                                                    perferendis adipisci praesentium.</p>
                                                <div class="conversation-item-time">12:30</div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </li>
                            <li class="conversation-item me">
                                <div class="conversation-item-side">
                                    <img class="conversation-item-image"
                                        src="https://images.unsplash.com/photo-1534528741775-53994a69daeb?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8OXx8cGVvcGxlfGVufDB8fDB8fHww&auto=format&fit=crop&w=500&q=60"
                                        alt="">
                                </div>
                                <div class="conversation-item-content">
                                    <div class="conversation-item-wrapper">
                                        <div class="conversation-item-box">
                                            <div class="conversation-item-text">
                                                <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quas, eos,
                                                    magni temporibus, placeat consectetur nobis incidunt dicta a culpa
                                                    vel esse. Facilis fugiat possimus eveniet accusamus dignissimos
                                                    pariatur inventore animi rem vero, eligendi obcaecati fugit quaerat?
                                                    Officia ex quod eaque maxime ipsam, tempore error laboriosam
                                                    laborum, magnam ipsum doloremque quas.</p>
                                                <div class="conversation-item-time">12:30</div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="conversation-item-wrapper">
                                        <div class="conversation-item-box">
                                            <div class="conversation-item-text">
                                                <p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Temporibus
                                                    debitis odio maiores perferendis ipsa repudiandae amet blanditiis
                                                    quod. Ullam, dolorum.</p>
                                                <div class="conversation-item-time">12:30</div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="conversation-item-wrapper">
                                        <div class="conversation-item-box">
                                            <div class="conversation-item-text">
                                                <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Accusantium
                                                    blanditiis ea, voluptatum, eveniet at harum minima maxime enim aut
                                                    non, iure expedita excepturi tempore nostrum quasi natus voluptas
                                                    dolore ducimus!</p>
                                                <div class="conversation-item-time">12:30</div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </li>
                        </ul>
                    </div>
                    <div class="conversation-form">
                        <div class="conversation-form-group">
                            <textarea class="conversation-form-input" rows="1" placeholder="Type here..."></textarea>
                        </div>
                        <button type="button" class="conversation-form-button conversation-form-submit"><i
                                class="ri-send-plane-2-line"></i></button>
                    </div>
                </div>
// start: chatlist
document.addEventListener('DOMContentLoaded', function() {
    var chats = document.querySelectorAll('.content-messages-chat');

    chats.forEach(function(chat) {
        chat.addEventListener('click', function() {
            chats.forEach(function(item) {
                item.classList.remove('active');
            });

            this.classList.add('active');
        });
    });
});
// end: chatlist

// start: Conversation
document.querySelectorAll('.conversation-form-input').forEach(function(item) {
    item.addEventListener('input', function() {
        this.rows = this.value.split('n').length;
    });
});

document.querySelectorAll('[data-conversation]').forEach(function(item) {
    item.addEventListener('click', function(e) {
        e.preventDefault();
        document.querySelectorAll('.conversation').forEach(function(i) {
            i.classList.remove('active');
        });
        document.querySelector(this.dataset.conversation).classList.add('active');
    });
});

document.querySelectorAll('.conversation-back').forEach(function(item) {
    item.addEventListener('click', function(e) {
        e.preventDefault();
        this.closest('.conversation').classList.remove('active');
        document.querySelector('.conversation-default').classList.add('active');
    });
});
// end: Conversation

Im expecting the conversation wrapper to always be scrolled down when you open it. There I added my html and javascript i didnt add the css since its not relevant. Its important to know that there are going to be multiple different chats, increasing the number on conversation-#number# by 1 per chat.

Iframe error: Unsafe attempt to initiate navigation for frame with origin A from frame with URL B

I have an React App with origin A.

In “/overview” page, I am loading an Iframe with url B from a different origin.

Links in url B is attempting to navigate to a route(/article) in my App with origin A. Then I get this error and no network request is fired:

“unsafe attempt to initiate navigation for frame with origin A from frame with URL B. The frame attempting navigation is neither same-origin with the target, nor is it the target’s parent or opener”

My code works fine locally, I was able to open links in iframe and it will redirect to my route(/article), but when I deployed it to our server, it is not working.

I tried create iframe with useEffect and set iframe.contentWindow.opener = window;
It does not work. looks like we can’t append childElement to another element with useEffect?

I saw some solution that ask me to set “sandbox” property for iframe. For now “sandbox” is not present in my iframe. the document says that means no restriction is applied. is that correct?

I’d like to try set whitelist of our deploy environment, but I am not sure how to do this.

Mock-ing Commander for Unit Testing

I am trying to determine the best way to unit test the main entry point into a CLI that I’ve built. The file that I’d like to Mock is here: https://github.com/mike-weiner/wlbot/blob/main/index.js

The first problem I’ve encountered is trying to determine if this file should even be unit tested. I’ve written unit tests for the underlying functions that Commander calls, so I’m wondering if there’s no real added benefit to testing this file.

The second problem I’m encountering is how to use jest.unstable_mockModule to mock Commander. I’ve read through the docs, but that was not all that helpful.

I have written quite a few tests using jest.unstable_mockModule for other parts of this CLI. As an example: https://github.com/mike-weiner/wlbot/blob/main/commands/weather/__tests__/current.test.js#L3-L26

Dynamically change EJS elements

Beginner question. I’m working on a project where I need to create a blog-type site with node/express/ejs. I’m stuck at the part where I need to display submitted posts and allow the user to view/edit/delete them. Here’s the part I’m stuck on:

<div class="post-tile">
  <div class="post-info">
    <img src="images/user1.svg" alt="user icon" width="30" />
    <h2 class="post-title-ex"><%= posts[displayID].title %></h2>
    <h3 class="post-author-ex"><%= posts[displayID].author %></h3>
  </div>
  <p class="post-content-ex"><%= posts[displayID].content %></p>
</div>
import express from 'express';
import bodyParser from 'body-parser';

const port = 3000;
const app = express();

app.use(express.static('public'));
app.use(bodyParser.urlencoded({ extended: true }));

app.listen(port, () => {
    console.log(`Listening on port ${port}`);
})

app.get('/', (req, res) => {
    let data = {
        posts: blogPosts,
        displayID: 0,
    };

    res.render('index.ejs', data);
  });

app.post('/submit', (req, res) => {
    let uName = req.body['user'];
    let title = req.body['title'];
    let content = req.body['post-content'];
    let postIDassign = blogPosts.length + 1;

    blogPosts.push(new Post(uName, title, content, postIDassign));

    res.redirect('/');
})

/* For blog posts */
const blogPosts = [];

function Post(user, title, content, postID) {
    this.user = user;
    this.title = title;
    this.content = content;
    this.postID = postID;
}

I’ve tried implementing a client-side javascript file to handle changing the posts based on an HTML dataset with this code:

const postSelection = document.querySelectorAll('.post-title');
const postDisplayTitle = document.querySelector('.post-title-ex');
const postDisplayAuthor = document.querySelector('.post-author-ex');
const postDisplayContent = document.querySelector('.post-content-ex');

const blogPosts = posts;

postSelection.forEach((post) => {
    post.addEventListener('click', () => {
        let ID = (post.dataset.postid) - 1;
        console.log(ID);
        displayID = ID;
    })
})

My issue is that I can’t figure out a way to update the displayID once it’s already rendered on the page. This is my first time using backend languages on a full project and I know there’s something very basic I’m missing, the entire premise may need to be rethought, etc.

How to stop an image from moving after being changed by a javascript button?

I`ve made a 2 buttons that run 2 functions to change the source of an image to a diffrent one. This works fine but whenever I change the source the image shifts slightly to the left and goes back to normal after changing source with the 2nd button back to the 1st image.

HTML

 <body>
        <div class="lightbulb">
            <img id="lightbulb" src="mini_mini_pngwing.com.png">
        </div>
        <div class="button">   
            <button id="button" type="button" onclick="bulbon()">Turn On</button>
            <button id="button2" type="button" onclick="bulboff()">Turn Off</button>
        </div>
    </body>

Javascript

     function bulbon() {
    if (document.getElementById("lightbulb").src = "mini_mini_pngwing.com.png") {
        (document.getElementById("lightbulb").src = "mini_lightbulbon.png");
    }  
    }
            function bulboff() {
    if (document.getElementById("lightbulb").src = "mini_lightbulbon.png") {
        (document.getElementById("lightbulb").src = "mini_mini_pngwing.com.png");
    }
    }

CSS

 .lightbulb {    position: fixed;
                            height: 10%;
                            width: 50%;
                            display: block;
                            margin: auto;
                            left: 650px;
                            top:125px;}

I tried to make a simple website with 2 buttons. One of them changes a lightbulb to be on, and another the lightbulb to be off. However for some reason the lightbulbs position changes whenever the 1st button is pressed and goes back to normal once the 2nd is pressed.

Ionic 7 with Angular makes only UI changes when Debbuger ist runing

I have an ion-select which should contain an ion-icon at the end. The icon should change depending on whether the ion-select is open or closed.
Problem:
My icon changes correctly when the ion-select is open but no longer when the ion-select is closed. Strangely enough, when I debug the behaviour, the ion-icon changes correctly both when closing and opening.

<ion-list lines="none">
      <ion-list-header class="header">{{'category' | translate }}</ion-list-header>
      <ion-item>
        <ion-select placeholder="{{'categoryFilter' | translate }}" interface="popover" (ionFocus)="setToggleIcon()" (ionDismiss)="setExpandIcon()" >
          <ion-select-option  *ngFor="let category of [1,2,3]; index as i">Apfel {{i}}</ion-select-option>
        </ion-select>
        <ion-icon class="toggleIcon" name="{{toggleIcon}}"></ion-icon>
      </ion-item>
      <hr class="border">
      </ion-list>



@Component({
  selector: 'app-maintenance-list',
  templateUrl: './maintenance-list.component.html',
  styleUrls: ['./maintenance-list.component.scss'],
})
export class MaintenanceListComponent  implements OnInit {
  protected toggleIcon:string = "chevron-down-outline";
  constructor() {
  }
  ngOnInit() {}

  setToggleIcon(): void {
    this.toggleIcon = 'chevron-up-outline';
  }

  setExpandIcon(){
    this.toggleIcon ="chevron-down-outline"
  }
}

Thank you for your help

Typescript Cannot find module after migrating to typescript

I recently migrated a small project from CommonJS to TypeScript, and I’m encountering a perplexing issue. The TypeScript compilation proceeds without any errors, yet when I run the server, I encounter the following error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/ivan/Documents/Projects/api/src/v1/routes/userRoutes' imported from /Users/ivan/Documents/Projects/api/src/index.js

Curiously, when I execute ls in the directory containing userRoutes, I can see that both the .ts and .js files are present. In index.ts, I’m importing userRoutes using the following statement:

import { userRouter as v1UserRouter } from './v1/routes/userRoutes';

Also inside userRoutes I have this export:

export const userRouter = router;

fs.cpSync is not a function

I am having an issue when I was trying to create or install the LightningJS 3 app using VS Code. I get this error:

npx: installed 5 in 9.028s 
fs.cpSync is not a function

I tried rebooting the computer and updating VS Code but still having issues, not sure what is going on.

Embedding nextjs project to an html page

I have made my custom chatbot using next js now i wanted to integrate it to other websites like html websites.

I have used the iframe tag in my html but it makes the beneath elements of parent website not clickable, is there anyway that i can click on the part of my parent element which are transparent or if there is any method through which i can integrate properly.