Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expect(element).to.have.style('height', '323px') #1393

Closed
ghost opened this issue Mar 1, 2018 · 7 comments
Closed

expect(element).to.have.style('height', '323px') #1393

ghost opened this issue Mar 1, 2018 · 7 comments

Comments

@ghost
Copy link

ghost commented Mar 1, 2018

How can I get the element height or width?

Something like:

cy.get(mainMenu).expect(element).to.have.style('height', '323px');
cy.get(mainMenu).expect(element).to.have.style('width', '20px');

Is it possible?

Maybe using this: https://github.com/darlanmendonca/chai-style ?

@ValerieThoma
Copy link

Can you try

cy.get('mainMenu').should('have.attr', 'height', '323');

Or reference the Guides on Assertions here for what you're looking for? https://docs.cypress.io/guides/references/assertions.html#Chai

@ghost
Copy link
Author

ghost commented Mar 1, 2018

Nothing.

I tried also:

expect(mainMenu).to.have.attr("height", "323");

In that page I don't see height or width.

I just need to get the height or wodth of an element.

How to?

@ValerieThoma
Copy link

Have you tried sharing this issue with the community in the Cypress Gitter channel?
https://gitter.im/cypress-io/cypress

@ghost
Copy link
Author

ghost commented Mar 1, 2018

Nope. I think this is at least a doc issue. Please don't close.

@brian-mann
Copy link
Member

@johnunclesam the assertion you're looking for is documented here: https://docs.cypress.io/guides/references/assertions.html#Chai-jQuery

It's to.have.css(....)

The way you most commonly use assertions is with .should() as documented here.

https://docs.cypress.io/guides/references/assertions.html#Common-Assertions

// assuming mainMenu is a string selector here
cy.get(mainMenu).should('have.css', 'height', ...)

When you have a direct element reference that's when you use expect(subject)

cy.get(mainMenu).should(($el) => {
  expect($el).to.have.css('height', ...)
})

@cjohn17
Copy link

cjohn17 commented Apr 4, 2019

// assuming mainMenu is a string selector here
cy.get(mainMenu).should('have.css', 'height', ...)

This mostly worked for me, except I get an error back that the expected value is 55, but the returned value is 55px. How to account for this?

@jennifer-shehane
Copy link
Member

@cjohn17

cy.get(mainMenu).should('have.css', 'height', '55px')

@cypress-io cypress-io locked as resolved and limited conversation to collaborators Apr 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants