首页 > 解决方案 > Behat 不调用 jQuery

问题描述

我在 symfony 4 中使用 behat 来测试消息的发送。当您选择主题“其他”时,会从 jQuery 中显示一个新字段。当我现场测试这段代码时,没有问题。但是从 behat 开始,没有调用 jQuery。Behat 选择了正确的“其他”选项,但没有出现新字段。

这是场景中的步骤:

/**
 * @Given /^I choose the subject "([^"]*)" in select "([^"]*)"$/
 * @param $topic
 * @param $select
 */
public function iSelectTheSubject($topic, $select)
{
  $this->selectOption($select, $topic);
}

这是我的 jQuery :

(function ($) {
            let selectSubject = $('#app_customer_service_taxon option');
            let inputOther = $('#app_customer_service_taxonOther').parent();
            let options = {
                action: 'click',
                html : 'other'
            };

            inputOther.hide();
            selectSubject.on(options.action, e => {
                $(e.currentTarget).html() === options.html ? inputOther.show() : inputOther.hide();
            });
        })(jQuery);

因此,当我开始 behat 时,它会以消息“元素不可交互”停止。就像根本没有调用 jQuery 一样。就像 selectOption 没有模拟点击一样。知道为什么吗?

标签: jquerybehat

解决方案


推荐阅读