What is the procedure for verifying the type of an element using chai?

Is there a way to determine if an element is either an "a" tag or a "div" tag? I've tried the following code, but it's not working as expected:

it('has no link if required', () => {
        const wrapper = shallow(<AssetOverlay asset={ assetsData[0] } shouldBeLinked />);
        expect(wrapper.find('.overlay-asset-link')).to.be.a('a');

        const wrapper1 = shallow(<AssetOverlay asset={ assetsData[0] } shouldBeLinked="false" />);
        //expect(wrapper1.find('.overlay-asset-link')).to.be.a('div');
    });

Answer №1

This is because chais type checking specifically looks at javascript types, not HTML tags.

If wrapper.find() returns a standard HTML element, you can test it using:

expect(wrapper.find('.overlay-asset-link').tagName).to.equal('A');

Please note: The tag name property is always in uppercase.

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

What is the best way to implement a 5-second delay after the timer reaches 00:00?

I am in the process of creating a countdown timer for an application. Once the timer reaches 00:00, I would like to add a 5-second delay before it starts counting down again. How can I achieve this using setTimeout()? function initiateTimer(duration, di ...

Combining the value of $(this) to create an identifier name

I am attempting to create a hover effect on an h1 element that triggers the glowing effect on a span element with an id that corresponds to the value of the h1. While I have successfully set up a glowing effect for a sentence, I am struggling to replicate ...

Ways to designate a tab as active

Having trouble styling the active tab in my tabbed menu created with Bootstrap. The active class seems to only affect the first tab. How can I make it work for all tabs? Check out this screenshot for reference. Below is the code snippet: <script ...

Retrieving the chosen date from a calendar using a jQuery function

Hey there, I need help with showing tasks created on a specific date by selecting that date from a full month calendar. There are multiple tasks created on the selected date, and I want to trigger a jQuery event to fetch data for that date. However, my i ...

Integrating AngularJS code into dynamically generated HTML using JavaScript

I am currently utilizing an outdated version of AngularJS (1.3). I have a page where I need to dynamically display different content based on database values. If the user interacts with the page and changes the database value, I want the displayed content ...

Linking the Twitter social button to the originating page

Is there a way to link the Twitter button to a referrer URL, so that all tweets will refer back to the page the visitor came from instead of the landing page itself? I've been able to do this with Facebook and G+ by using a href within the script and ...

The error message "props.text is undefined in React Native" indicates that there is an issue with accessing the property text within

//**// import { StatusBar } from 'expo-status-bar'; import {StyleSheet, Text, View, Button, TextInput, ScrollView, FlatList} from 'react-native'; import {useState} from "react"; import GoalItem from "./components/GoalItem"; export defau ...

Removing cookies after sending a beacon during the window unload event in Chrome

Here's the situation: I need to make sure that when the browser is closed or the tab is closed, the following steps are taken: Send a reliable post request to my server every time. After sending the request, delete the cookies using my synchronous fu ...

Ways to display a JSON object in CSV format

Is there a way to export a JSON object to a CSV file, where the sub-fields contain arrays of objects? I am unsure how to properly represent this embedded data in the CSV format. ...

The error message "TypeError: Cannot read property 'get' of undefined in mounted hook" is displayed when trying to access a property that is undefined

Currently, I am utilizing Jest for unit testing within Nuxt.js. Below is an example of my mounted hook: async mounted(){ try{ var response = await this.$axios.get("api_url here"); this.result = response.data; } catch(e){ console.log ...

`Apply event bindings for onchange and other actions to multiple elements loaded via ajax within a specific div`

My form includes various input fields, dropdowns, and text areas. Upon loading, jQuery locates each element, sets its data attribute to a default value, attaches an onchange event, and triggers the change event. The issue arises when some dropdowns are d ...

Issues arise with req.body being undefined when using node.js in conjunction with Express version 4.16.X and Body-Parser version

Recently, I began using node.js to construct a RESTFul API. Currently, my focus lies in inserting data through POST requests with JSON in the body. However, I encountered an issue where the req.body always returned as undefined. Upon investigating further ...

Vue function that inserts <br> tags for addresses

My Vue filter retrieves and combines address details with a , Vue.filter('address', (address, countryNames = []) => { const formattedAddress = [ address?.name, address?.company, address?.add1, address?.add2, address?.town ...

Guide to refreshing the main screen in React Native Expo post login with a StackNavigator

I have been working on my first application using React Native Expo and have made good progress. However, I am facing an issue where the user logs in successfully but the screen does not change. Can anyone help me with this problem? Below is the code for ...

Unable to utilize zoom and drag functionality with React-d3-tree in Next.js version 13

I've encountered an issue while working on a Next.js 13 project using the react-d3-tree library to render a tree structure. The problem arises with the zoom and drag functionalities not working consistently on the client side. Initially, they worked o ...

How to achieve the functionality of ocibindbyname in JavaScript

I am currently utilizing an HTA page that is coded in JavaScript to monitor various Oracle tables. My goal is to optimize the Oracle query caching by using bind variables, similar to how I implemented it in a PHP environment with this code: $sql = "selec ...

Create a duplicate of the information stored within the $scope variable

Suppose there are multiple variables stored in a $scope and the objective is to create a new object that only includes those variables, excluding all the internal Angular-related data. The specific names of the $scope variables may not be known. This can ...

Encountering ERR_EMPTY_RESPONSE when using the $.POST method

I have been struggling with a issue on my social networking site that includes chat functionality. I have utilized the $.post method extensively across multiple pages, and it generally functions well except for a specific page called message.php where user ...

What is the best way to show the previous month along with the year?

I need help with manipulating a date in my code. I have stored the date Nov. 1, 2020 in the variable fiscalYearStart and want to output Oct. 2020. However, when I wrote a function to achieve this, I encountered an error message: ERROR TypeError: fiscalYear ...

Having trouble utilizing two components in Vue.js

I'm brand new to working with Vue and I've encountered an issue: Below is my index.html file where I have used two custom tags - aas and task : <!DOCTYPE html> <html> <head> <title></title> </head> <bo ...