Use `should.have.property` to confirm the existence of a specific key-value pair within

I am trying to validate the existence of a key-value pair in an object using should.js syntax like this:

cy.gey(selector).should('have.property', 'Company Feature: ', ['open space ']);
. However, I encountered this error message
Error: AssertionError: expected { Object (Company Feature: , Name: ) } to have property 'Company Feature: ' of [ 'open space ' ], but got [ 'open space ' ]
. I'm not sure which part is causing the mismatch or if it's a bug within should.js?

// debug output
{
    "Company Feature: ": [
        "open space "
    ],
    "Name: ": [
        "John, Amazon "
    ]
}
// test.ts
cy.gey(selector).should('have.property', 'Company Feature: ', ['open space ']);



// html
<div class="container">
    <span>
        <span class="title">Company Feature: </span>
        <span class="text">open space </span>
    </span>
    <span>
        <span class="title">Name: </span>
        <span class="text">John, Amazon </span>
    </span>
</div>

Answer №1

The main issue here is that you are referencing different instances of the array. To solve this, make sure to reference the same instance of the array like this:

const featureList = [
        "open space "
    ];
const TestData = {
    "Company Feature: ": featureList,
    "Name: ": [
        "John, Amazon "
    ]
}
// test.ts
cy.get(selector).should('have.property', 'Company Feature: ', featureList);

Alternatively, you can use .deep in the chain to check against the structure. Check out the documentation for more information:

// test.ts
cy.get(selector).should('have.deep.property', 'Company Feature: ', featureList);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing AJAX within Django to remove a data entry in a database table defined by a model

I'm working on a project where I need to remove a row representing a model from the DB without having to reload the page. Currently, I have an X icon on the left side that hides the row using .hide('slow'). However, I am looking for a way to ...

Every time I attempt to execute route.js in my API folder, I encounter a persistent 404 error

Project Structure: https://i.stack.imgur.com/qMF6T.png While working on my project, I encountered an issue with a component that is supposed to call an API function. However, it seems like the file is not being found. I have double-checked the directory ...

What is preventing me from retrieving these JSON values?

One of the functionalities on my website involves making an AJAX call to retrieve a member's profile information for editing purposes. The code snippet responsible for this operation is shown below: function loadProfileData() { var ...

Storing a byte array in a local file using JavaScript: A Step-by-Step Guide

Recently, I encountered an issue while working with an openssl certificate. Specifically, when I tried to download the certificate from my API, it returned byte arrays that I needed to convert to a PEM file in order to access them through another API. The ...

Searching for a location path with parameters does not lead to navigation to the next page

I am trying to pass a parameter to the next page (edit page) by clicking on an edit button. The code I have tried is not working as expected. When I click on the button, the URL is displayed correctly but the page shows up blank and the controller does not ...

Testing Angular Components: Ensuring Proper Unit Testing of Public Members Intended for HTML Input Only

How can Angular's ng test --code-coverage help with unit testing public variables that are strictly used as direct input in HTML? https://i.sstatic.net/z6j1O.png These variables are eventually placed into other components like this: <ctrl-grid ...

The website functions perfectly on a local server, but encounters issues when compiled using the npx vite build command

As I work on building my website, I've come across a deployment issue that's causing quite the headache. Following the documentation for Vite and three.js found here, I successfully installed both tools and completed my site. However, running npx ...

Angular so that the autocomplete field is filled with information retrieved from a PHP URL

I am currently utilizing an autocomplete field that needs to fetch data from a MySQL database based on a PHP (YII2) action. The autocomplete field is currently being populated statically. Below is the code used to populate the autocomplete field: app.cont ...

Make sure to wait for the scrollTo function to finish before executing any other commands

I have a sleek scrolling directive in my AngularJS app that automatically scrolls to the bottom of the page. I want this command to execute only after the scrolling has completed. Currently, I trigger the scroll function and then use $('#comment-input ...

When the page is refreshed, Angular and JWT roles mysteriously vanish into thin

Currently, I am developing a CRUD application with an authentication component where I'm using JWT roles to manage the navigation between pages. This implementation ensures that once a user logs into the application, they will only see menu links rele ...

Using a jQuery selector to specifically target th elements for filtering

My code includes: var rows = $table.find('tbody > tr').get(); This line retrieves all rows in the table. But since not all tables may have tbody and thead explicitly defined, I must identify and remove any rows that contain .children('t ...

Utilize Jquery for Parsing a Json Document

I am currently facing challenges parsing a JSON file into my HTML page. Below is the structure of my JSON file: { "menu":[ { "id":"contact", "leaf":true, "description":"testing", "link":"", "content":" ...

The error message "NodeJS-Typescript-Yarn : Error: Module 'd3' not found" is displayed

I encountered an issue with importing d3 in my project. I am using [email protected] and Yarn. The problem arises when the file Layout.ts (Layout.js) tries to import d3, resulting in an error. import * as D3 from "d3"; The error persists ev ...

Online Adventure - Saving Conversations

I am interested in developing an RPG using JavaScript. The game will involve a significant amount of dialog. While I have knowledge of PHP and MySQL, I am new to XML. My queries are: Would it be more efficient to store the dialog in a MySQL database and ...

Exploring Vue JS: A guide to using the onChange event to dynamically update input values

I am currently utilizing the npm package vue-range-component to adjust values via a slider, which then dynamically updates in the input field. However, I'm encountering an issue with applying the onChange event for inputs. I need to have the ability ...

Unable to send data to controller when clicking on checkbox in CodeIgniter

Learning about CI and facing an issue with the following code: The Controller displays country values dynamically from the database, and I want to pass a value to my controller when a specific checkbox is clicked. This is the code for my view: <?php ...

assign a category to the initial item in the array

I need assistance with jQuery array elements... <div id="holder"> <div class="X">X</div> <div class="X">X</div> <div class="X">X</div> <div class="Y">Y</div> <div class="Y ...

The process of uploading a file is interrupted by an AJAX Timeout

My HTML form includes a file input field that utilizes AJAX to upload the selected file, complete with a progress bar. However, I encountered an issue where the request would hang without any response. To prevent this from happening in the future, I aim t ...

Unable to send message using window.parent.postMessage when src is set to "data:text/html;charset=utf-8" within an iframe

I'm currently working on a project to develop a compact editor that allows users to edit HTML using an iframe. I'm passing an HTML string into the src attribute as data:text/html, but I'm encountering challenges with communication in the par ...

What is the best way to implement async/await at the top level of my code?

After researching extensively on async/await, I decided to experiment myself. However, I am struggling to understand why the following code snippet does not work as expected: async function main() { var value = await Promise.resolve('Hey there&a ...