Cypress has a unique workflow that is based around baking in as many tests as possible into its default behavior. Before it simulates the click on the element containing "Family", it checks for actionability. This is a built in test that will fail if the element is hidden, display:none
(that's the case here), size 0,0, etc. Only after it passes that test will it simulate the action on the element containing 'Family'.
You can override the actionability check by using .click({force:true})
, but then you lose the guarantee that the user would actually be able to find and click on the element.
The proper way to do this test is to trigger the dropdown menu so that the element becomes visible, and then do the click. Here's what you would do if you wanted to find the "Genre" menu item, reveal the dropdown menu, and click the "Family" item:
describe('Hover Menu',()=>{
it('can click on a genre sub-menu item',()=>{
cy.get('#menu').contains('Genre').next('.sub-menu').then($el=>{
cy.wrap($el).invoke('show')
cy.wrap($el).contains('Family').click()
})
})
})
Here, show
is a jQuery method that modifies CSS properties to make the element visible.
cy.wrap($el)
turns a jQuery element into a Cypress Chainer, which you can then call Cypress commands on.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…