2014-09-29 96 views
6

我們在我們的Rails 4.1應用程序中開始了整合Reactjs的過程。事情是,現在很多功能都被破壞了。水豚,Poltergeist和Reactjs - 'undefined'不是函數

下面是測試的堆棧:

  • 黃瓜
  • 水豚
  • 鬼驅(經由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-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' 
+0

PhantomJS 1.x沒有'Function.prototype.bind'。你需要一個[shim](https://github.com/ariya/phantomjs/issues/10522#issuecomment-39248521),但我不知道如何使用這個墊片作爲你的特定技術堆棧。相關:[爲PhantomJS綁定polyfill](http://stackoverflow.com/questions/24224323/bind-polyfill-for-phantomjs)。在CasperJS中,你會這樣做[this](http://stackoverflow.com/questions/25359247/casperjs-bind-issue)。如果你找到答案,不要忘記回答你自己的問題。 – 2014-09-29 15:06:32

回答

7

我找到了解決辦法。你需要使用shim。我把文件放在vendor/assets/javascripts/es5-shim.js

之後,你需要初始化這個墊片。請注意,墊片應在之前反應的初始化,這是至關重要的!

的application.js

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

之後,測試開始重新工作。

+0

謝謝!有用! – 2015-11-30 15:58:59

相關問題