加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Capybara,Poltergeist和Reactjs – ‘undefine

发布时间:2020-12-16 23:20:56 所属栏目:百科 来源:网络整理
导读:我们在Rails 4.1应用程序中启动了集成Reactjs的过程.问题是现在有很多功能被破坏了. 这是测试的堆栈: 黄瓜 水豚 恶作剧者(通过phantomjs) Rspec 例如,有黄瓜功能: @javascript @servicesFeature: Manage Service Scenario Outline: Publish and archieve G
我们在Rails 4.1应用程序中启动了集成Reactjs的过程.问题是现在有很多功能被破坏了.

这是测试的堆栈:

>黄瓜
>水豚
>恶作剧者(通过phantomjs)
> Rspec

例如,有黄瓜功能:

@javascript @services

Feature: Manage Service
  Scenario Outline: Publish and archieve
    Given the individual user
    When I visit services page
    And I click on I18n translation for key "views.labels.add"
    And I fill service's fields and choose price as "<price>"
    And I click on I18n translation for key "<submit_btn>"
    Then I should see I18n translation for key "<message>"
    And Created service should have 1 tag

  Examples:
    | submit_btn                 | price      | message                                       |
    | views.labels.publish       | fixed      | views.messages.notices.add.created            |
    | views.labels.publish       | negotiated | views.messages.notices.add.created            |

当我运行此测试时,我看到此错误:

One or more errors were raised in the Javascript code on the page. If you don't care about these errors,you can ignore them by setting js_errors: false in your Poltergeist configuration (see documentation for details).

  TypeError: 'undefined' is not a function (evaluating 'RegExp.prototype.test.bind(
      /^(data|aria)-[a-z_][a-zd_.-]*$/
    )')
  TypeError: 'undefined' is not a function (evaluating 'RegExp.prototype.test.bind(
      /^(data|aria)-[a-z_][a-zd_.-]*$/
    )')
      at http://127.0.0.1:53686/assets/application.js:32342
      at http://127.0.0.1:53686/assets/application.js:28807 in s
      at http://127.0.0.1:53686/assets/application.js:28807
      at http://127.0.0.1:53686/assets/application.js:37581
      at http://127.0.0.1:53686/assets/application.js:28807 in s
      at http://127.0.0.1:53686/assets/application.js:28807
      at http://127.0.0.1:53686/assets/application.js:32910
      at http://127.0.0.1:53686/assets/application.js:28807 in s
      at http://127.0.0.1:53686/assets/application.js:28807 in e
      at http://127.0.0.1:53686/assets/application.js:47260
      at http://127.0.0.1:53686/assets/application.js:28807
      at http://127.0.0.1:53686/assets/application.js:47262 (Capybara::Poltergeist::JavascriptError)
  ./features/step_definitions/service.steps.rb:16:in `/^the individual user$/'
  features/service/new.feature:9:in `Given the individual user'

解决方法

我找到了解决方案.你需要使用 shim.我把文件放在vendor / assets / javascripts / es5-shim.js中.

之后你需要初始化这个垫片.请注意,垫片应该在反应初始之前进行,这很关键!

的application.js

//= require es5-shim
//= require react
//= require react_ujs

之后测试开始再次起作用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读