简体   繁体   中英

How to select boolean value with Cypress select method without type error?

I'm trying to write cypress test where if user selects True then font size changes. The code below works if I change the type to string, but fails on boolean with following type error: "Argument of type 'boolean' is not assignable to parameter of type 'string | number | (string | number)[]"

setActive: (value: boolean): Cypress.Chainable<JQuery> => 
  cy.get('#control-active').select(value)

I want this setActive method to be used in following test scenario

it('active can be set', () => {
  labelControls.setActive(true);
  getLabel().should('have.css', 'font-size', '14px'); 

I checked cypress document and it seems "select" does not support boolean. Is there a way where I can get "select" to accept boolean value as well?

The .select() command is for dropdowns, but if your values are true/false then you have a checkbox.

Cypress provides .check() and .uncheck()

setActive: (value: boolean): Cypress.Chainable<JQuery> => 
  if (value) {
    cy.get('#control-active').check()
  } else {
    cy.get('#control-active').uncheck()
  }

I'm making a guess here, it would help confirm if you can post the DOM.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM