Skip to content

Commit 66dc268

Browse files
committed
Check fancySelect.choicesInstance is set
After merging of joomla#46621, Cypress System Tests fail more often (but not always) with `(uncaught exception)TypeError: Cannot read properties of undefined (reading 'clearChoices')`. However, investigations have shown that this also happened before, but not as often. It appears that Cypress speeds up page loading and XHR timing, and with the newly added `onChange()`, this causes Cypress to fail with an uncaught exception. This simple *hack* prevents the crash. If you have a better implemention, you are welcome to share it.
1 parent bb2a150 commit 66dc268

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

build/media_source/com_menus/js/admin-item-edit.es6.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,16 @@ const onChange = ({ target }) => {
5757
const data = JSON.parse(response);
5858
const fancySelect = document.getElementById('jform_parent_id').closest('joomla-field-fancy-select');
5959

60-
fancySelect.choicesInstance.clearChoices();
61-
fancySelect.choicesInstance.setChoices([{
60+
const choices = fancySelect?.choicesInstance;
61+
62+
// If the field (or its Choices instance) isn't ready yet as in Cypress run, don't crash.
63+
if (!choices) {
64+
return;
65+
}
66+
67+
choices.clearChoices();
68+
choices.setChoices([{
69+
6270
id: '1',
6371
text: Joomla.Text._('JGLOBAL_ROOT_PARENT'),
6472
}], 'id', 'text', false);

0 commit comments

Comments
 (0)