我们开始在 Rails 4.1 应用程序中集成 Reactjs
。问题是现在很多功能都被破坏了。
这是测试堆栈:
- cucumber
- capybara
- 恶作剧(来自 phantomjs)
- R规范
比如有 cucumber 特征:
@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-z\d_.\-]*$/
)')
TypeError: 'undefined' is not a function (evaluating 'RegExp.prototype.test.bind(
/^(data|aria)-[a-z_][a-z\d_.\-]*$/
)')
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
中。
之后您需要初始化这个垫片。请注意,垫片应该在 react 的初始化之前,这很关键!
application.js
//= require es5-shim
//= require react
//= require react_ujs
此后测试再次开始工作。
关于ruby-on-rails - Capybara、Poltergeist 和 Reactjs - 'undefined' 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26102903/