mercredi 30 septembre 2020

cypress and select2 not triggering on select

I'm new to cypress and working my way through various examples to support testing of my app.

I've got a select box which uses select2 - I can successfully select the item from the dropdown box but cypress is not then triggering the select event from which my code is running off.

How can I get Cypress to select the item and then trigger the select event?

Here's my test code:

cy.get('select[name=people] > option')
            .eq(3)
            .then(element => cy.get('select[name=people]').select(element.val(), {force:true}));

This succesfully selects the 3rd item in the drop down

I then have this code which takes actions based on the selection:

$('#people').on("select2:select", function (e) {
                var selectId = $(this).select2('data')[0].id;
                var castName = $(this).select2('data')[0].text;
                $('option:selected', this).prop('disabled', 'disabled');
                addCastTableRow(selectId, castName);
                initRemoveCastButton();
                $(this).select2();

            });

Any thoughts appreciated

Thank you

Aucun commentaire:

Enregistrer un commentaire