How to test vuex state and mutations correctly?

tell me how to test mutations and state correctly. I have a modal window component, it is rendered if the showModal property in the state is true. And there is an event that causes a mutation that changes the property.
How to check that after the event is called, the component is no longer rendered? Do I need to import the actual vuex storage?

<template>
  <div>
   <transition name="fade" appear>
     <div ref="modal" class="modal-overlay"
       v-if="isShow"
       @click="close">
     </div>
   </transition>
 <transition name="pop" appear>
  <div class="modal"
       role="dialog"
       v-if="isShow"
  >
  <div class="layer">
      <slot name="content"></slot>
    </div>
  </div>
</transition>
</div>
import { mapState } from 'vuex'

export default {
  name: "VModal",
  computed:{
    ...mapState({
      isShow: state => state.showModal
    })
  },
  methods:{
    close(){
      this.$store.commit('SHOW_OR_HIDE_MODAL', false)
    }
  }
}




import Vuex from "vuex"
import { mount, createLocalVue } from "@vue/test-utils"
import VModal from '../../assets/src/components/VModal'
const localVue = createLocalVue()
localVue.use(Vuex)

describe('testing modal', () => {
let mutations
let state
let store

beforeEach(() => {
    state = {
        showModal: true
    }
    mutations = {
        SHOW_OR_HIDE_MODAL: jest.fn()
    }
    store = new Vuex.Store({ state, mutations })
})
test('check close modal', async () => {
    const wrapper = mount(VModal, {
        store, localVue
    })

    await wrapper.find(".modal-overlay").trigger("click")

    await wrapper.vm.$nextTick();
    expect(wrapper.find(".modal-overlay").exists()).toBe(false)
    expect(wrapper.find(".modal").exists()).toBe(false)
 })
})

And I have index.js with store

enter image description here

But in test after click I get error
enter image description here

I understand what I’m doing wrong, but I can’t figure out how to properly test vuex, sorry for the stupid question, any help would be appreciated

JavaScript send data from input field to ajax request

I have following Code. But the String in the Database is empty. Why does it not work to get the string from the input field?

HTML

 <div id="todo">
   <h2>Todo Liste</h2> 
   <form method="get">
     <input type="text" name="username" placeholder="name" required>
     <input type="text"  class="inputField" name="inputData" id="myInput" placeholder="title"  required><br><br>
     <span onclick="newElement(); sendData(this.value)" class="addBtn">Add</span><br><br>
    </form>

JavaScript

function sendData(str) {
  const xmlhttp = new XMLHttpRequest();
  xmlhttp.onload = function() {
    document.getElementById("txtHint").innerHTML = this.responseText;
  }
  xmlhttp.open("GET", "saveData.php?q=" + str);
  xmlhttp.send();
}

Error: “‘node’ not recognized as…” when I try to run the file with package.json script

I am learning Node, and I get the error “node is not recognized as an internal or external command” when I try to run my project with npm start or npm run start. It works if I use node index.js. I have checked the Node Environment Variables, my Node version is v16.13.2 and npm is 8.4.1.
My package.json:

{
  "name": "node-express-practica",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "license": "ISC",
  "devDependencies": {
    "@babel/cli": "^7.17.0",
    "@babel/core": "^7.17.2",
    "@babel/preset-env": "^7.16.11",
    "@babel/register": "^7.17.0",
    "nodemon": "^2.0.15"
  }
}

Uncaught TypeError: Cannot set properties of null (setting ‘onchange’) [duplicate]

Hi all whats wrong with this script? getting Uncaught TypeError: Cannot set properties of null (setting ‘onchange’) Thanks

IsLegalPerson=document.getElementById('IsLegalPerson');
    org=document.getElementById('org');
    inp_org=document.getElementById('CustomerOrganization');
    IsLegalPerson.onchange=function(){
        if(this.value=='true')org.style.display='block';
        else org.style.display='none';
    };
    
    document.body.init_checkout=initListeners;
    document.body.updated_checkout=initListeners;
    function initListeners(){

      var btn = document.querySelector('#place_order');
      if (!btn) return
      
      btn.addEventListener('click', function(e){
        if(IsLegalPerson.value=='false'&&inp_org.value==''){
            e.preventDefault();
        
            inp_org.value='tmp_value';
            btn.click();
        }   
      })
      
    }

GSAP SplitText Hover Effect faulter

I’ve created an array of nav links within my navigation. Upon hovering over top of a link, the text moves upward, into overflow which is hidden and is replaced by the same text moving out of overflow from ben beneath. I additionally want to incorporate a GSAP SplitText attribute whereupon hover, not only does the word move upward but the individualized characters stagger upward. However, I’m having trouble creating the code within my pre-existing commands

This is my code:
https://github.com/JulesSC/Custom_Nav.git

If anyone has any advice I’d greatly appreciate it!

Can someone explain me how does the operation inside reduce method affect the object in outer scope?

I am looking into a code which is to strip some prefix url from object properties.

const strip2 = (object, path) => {
  const keys = [path];
  const pathArray = keys[0].split('.');

  pathArray.reduce((prevObj, key, index) => {
    if (!prevObj[key]) {
      return null;
    }
    if (Array.isArray(prevObj[key])) {
      return prevObj[key].map(item => strip2(item, pathArray[index + 1]));
    }
    if (index === pathArray.length - 1) {
      prevObj[key] = prevObj[key].replace('/hello', '');
    }
  }, object);

  return object;
};

strip2(
  {
    title: 'this is the title',
    menu: [
      {
        link: '/hello/contact',
        title: 'Contact Us',
      },
      {
        link: '/hello/faq',
        title: 'Faq',
      },
    ],
  },
  'menu.link'
);

\ it will return
{
  title: 'this is the title',
  menu: [
    { link: '/contact', title: 'Contact Us' },
    { link: '/faq', title: 'Faq' }
  ]
}

I tried to trace it and I can’t understand how does the replace method inside reduce affects the object in outer scope.

‘Failed to compile.’ error when deploying react app to gh-pages

I’m getting this error when I try to deploy my react app to github pages:

Failed to compile.
The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script

I tried to deploy another very simple react app (the default one) to github and faced no error and was deployed easily. But somehow, when I try to deploy this app, it doesn’t work and shows the error that I mentioned earlier (The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script)

Can anyone help?

Here’s my github repo that I’m trying to deploy: https://github.com/Muhammad-Abdullah-Zeeshan/todo-list-react

css not updating after re-redering component in redux react

I am trying to create a webpage using React.
used redux for data access.

My problem is that when I click on any product, it shows me a perfect page, but if I go back and then again click on another product, my page shows me the data of the new product, but it does not change the photo height in CSS.

home page

product 1product 2(its doesnt changing first image height)

export const productDetailsReducer = (state = { product: {} }, action) => {

switch (action.type) {
    case PRODUCT_DETAILS_REQUEST:
        return {
            loading: true,
            ...state     <------i am sending the previous state
        }
    case PRODUCT_DETAILS_SUCCESS:
        return {
            loading: false,
            product: action.payload,
        }
    case PRODUCT_DETAILS_FAIL:
        return {
            loading: false,
            error: action.payload
        }
    case CLEAR_ERRORS:
        return {
            ...state,
            error: null
        }

    default:
        return state
}

Appending a Child element to a parent node using AppendChild()

Button to call JS Method:

<button class="btn btn-cta btn-next add-cost-item-btn" onclick="addNewItem()" type="button">
    <span class="name">Add New Item</span>
</button>

Js Method:

function addNewItem() {
  let divOne = document.querySelector('.js-div-item');
  let grid = document.querySelector('.js-cost-input-grid');
  grid.appendChild(divOne);
}

HTML

<div class="row cost-input js-cost-input-grid">
  <div class="input-label cost-input-child">Item</div>
  <div class="input-label item-cost cost-input-child js-div-item">
     @Html.TextBoxFor(m => m.Item, new { @class = "form-control currency-input", placeholder = "Item name" })
</div>
               

When trying to append a child onto js-cost-input-grid nothing is happening?

I tried appending a the result of document.createElement('p') – which worked fine. Why does it not work with my divOne?

Search for value contained in array of objects in property of object contained in array

can someone help me with this?
I need a function that given a fieldID, searchs within objects and returns the objectID that fieldID is in.

  const objects = [
    {
      objectID: 11,
      fields: [
        { id: 12, name: 'Source ID' },
        { id: 12, name: 'Source ID' },
      ],
    },
    {objectID: 14,
      fields: [
        { id: 15, name: 'Creator' },
      ],},
    {objectID: 16,
      fields: [
        { id: 17, name: 'Type' },
        { id: 18, name: 'Name' },
        { id: 19, name: 'Description' },
      ],},
  ];

So it would be something like this…

getObjectID = (fieldID) => {
  (...)
  return targetObjectID
}

How to obtain the left, right, top and bottom position of scroll in a div in HTML with Javascript

I would like to draw a <div> box with fixed height, width and scrollbars and register the location of the scrolled view. I have found the function scrollTop but don’t know how to get the bottom scroll location.

  1. Which CSS do I need to draw the box with scrollbars?
  2. How can I access the left, right, top and bottom position inside (relative to) the box with Javascript?

I would use these 4 numbers to draw a <div> inside.

Object is overwritten by new one in array

I know there are similar questions related to this but none of them seems to solve the issue for me.

How do prevent the push method from overwriting the existing object in the array?

Pardon the variable x by the way.

const investorValues = state.investorSelected;
    const categoryValues = state.categoryCheckbox;

    const listAsFavourite = {
        listName: "",
        listDescription: "",
        listItems: {
            categories: [],
            investors: [],
        },
        saveAsOpen: state.saveAsOpen === false ? !state.saveAsOpen : state.saveAsOpen,
        saveAsComing: state.save

> Blockquote

AsComing === false ? !state.saveAsComing : state.saveAsComing
    };

    if (investorValues !== null) {

        listAsFavourite.listItems = {
            ...listAsFavourite.listItems,
            investors: investorValues
        }
    }

    if (categoryValues !== null) {
        listAsFavourite.listItems = {
            ...listAsFavourite.listItems,
            categories: categoryValues
        }
    }

    const saveFavouriteList = () => {
        const favouriteList = []

        if (state.favouriteListName === "") {
            alert.error("List must have a title")
        } else {

            const x =  {
                ...listAsFavourite,
                listName: state.favouriteListName,
                listDescription: state.favouriteListDescription
            }
            
            favouriteList.push(x);


            localStorage.setItem("FAVOURITE_lIST", JSON.stringify(favouriteList));

            alert.success("List created");

            removeFavouriteListModal();
        }
    }

Any sites, where I can take JS tasks and post my solution on github

Could you recommend me any sites, where I can take JavaScript tasks, solve them and then post my solutions for those tasks on my github page? I mean I’d like to use it as my portfolio to demonstrate my skills to those, who can hire me. I asked about this on codewars, but in the Code of conduct they ask not to do so, though it seems that there’s no penalty for this. Any recommendations? Thanks in advance

prompt loads before anything else

hay if anybody understand why is prompt showing up even before the console printing
i appreciate the help

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>promptheadache</title>
</head>

<body>
    <script>
    
        console.log('i should appear first on the console')

        var promptInput = prompt('I'm am here befor anything else')

    </script>
</body>

</html>