Reputation: 3900
My template:
<template>
<q-item tag="label" v-ripple>
<q-select
borderless
stack-label
emit-value
map-options
multiple
class="full-width"
v-model="model"
:options="options"
:label="name"
>
<template v-slot:after>
<q-btn
data-test="btnMultipleDropDownSetting"
round
dense
flat
color="primary"
icon="done"
@click="multiSelectionCompletes"
:disable="submitButtonDisable"
/>
</template>
</q-select>
</q-item>
</template>
Test code:
it('Verify Multiple-Select from auto-generated page', () => {
cy.get('[data-test="multidropdown-setting-4"]').find('label').should('contain', "Auto Generated Multi-Selection box");
cy.get('[data-test="multidropdown-setting-4"]').find('label').click();
cy.get('[data-test="multidropdown-setting-4"]').find('label').select(["Option 1"]);
cy.get('body').click();
cy.get('[data-test="multidropdown-setting-4"]').find('span').should('have.text', 'Option 1');
}); // XXX
Cypress fails with very strange error without even running the test yet:
Upvotes: 0
Views: 237
Reputation: 604
I was facing the same issue. Got it to work by going through the quasar testing Github repo. Sample Code if anyone is facing similar issue.
cy.dataCy('select').click()
cy.withinSelectMenu({
persistent: true,
fn: () => {
cy.contains('Option One').click()
},
})
Upvotes: 0
Reputation: 31974
The Quasar Cypress helpers overrides the .select()
, see cypress.overrides.ts
if (subject.hasClass('q-select')) {
if (Array.isArray(valueOrTextOrIndex)) {
if (!subject.hasClass('q-select--multiple')) {
throw new Error(
'Cypress: select command with array param can only be used with a multiple select',
);
}
} else {
valueOrTextOrIndex = [valueOrTextOrIndex];
}
This shows that the
<q-select
...
multiple
>
should throw an error (not the one you get, but the one shown above) when you pass a single value into the .select()
.
Try passing an array
cy.get('[data-test="multidropdown-setting-4"]')
.find('label')
.select(["Option 1"])
BTW The error message you get above isn't coming from the .select()
override, but from the portal
helper. I haven't traced back to that point, but try with the above mod first as it seems most likely.
This might also work:
cy.get('[data-test="multidropdown-setting-4"]')
.find('label')
.click(); // open the menu
cy.withinSelectMenu( // should only be one menu open
{persistent: true}, // this means you have a multiple select
() => {
cy.get('.q-item[role=option]').contains("Option 1").click();
})
Upvotes: 1