【发布时间】:2017-10-25 15:32:45
【问题描述】:
我在一个新项目中遇到了这个奇怪的错误,我想使用 Angular 并通过虚假数据进行 ajax 搜索。搜索正在工作,但是当我尝试使用 PhantomJS、Capybara、Rspec、Webpack 和 angular 环境创建测试时,会发生错误。 版本:
- phantomjs: 2.1.1(在控制台中使用
phantomjs -v
签入 - webpacker (3.0.2 3b09f78)
- websocket 驱动程序 (0.6.5)
- websocket 扩展 (0.1.2)
- rspec-core (3.7.0)
- rspec-rails (3.7.1)
- 水豚 (2.15.4)
这是我的测试规范/features/product_search_spec.rb:
require 'rails_helper'
feature 'product search' do
let(:email) {"username@mail.dk"}
let(:password) {"passwordpassword"}
before do
create_test_user(email, password)
create_product("Christan", "Zebra", "Andersen")
create_product("Mathias", "Aude", "Zebra")
create_product("Zebaa", "Zulu", "Hest")
create_product("Aaaaaaaaa", "Zebra", "Aaaaaaa") # Første produkt, der bliver vis
end
scenario "Search by title" do
visit root_path
fill_in "Email", with: email
fill_in "Password", with: password
click_button "Log in"
click_link "Gå til produktsøgning"
sleep 1
puts page.body
within ".search-form" do
fill_in "keywords", with: "Zeb"
end
within "section.search-results" do
expect(page).to have_content("Zebra")
list_group_items = page.all("ol li.list-group-item")
expect(list_group_items.count).to eq(4)
expect(list_group_items[0]).to have_content("Zebaa") # Er det sorteret rigtigt?
end
end
end
def create_test_user email, password
User.create!(
email: email,
password: password,
password_confirmation: password
)
end
# For at jeg og senere udvikler tydeligt kan se hvilken test-data, som det er vi arbejder med.
def create_product title, subtitle, authors
title ||= Faker::Internet.username
subtitle ||= Faker::Internet.domain_name
authors ||= Faker::FamilyGuy.character
Product.create!(
title: title,
subtitle: subtitle,
authors: authors
)
end
当我运行rails spec SPEC=spec/features/product_search_spec.rb
我在终端中收到错误:
product search Search by title
Failure/Error: click_link "Gå til produktsøgning"
Capybara::Poltergeist::JavascriptError:
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 constructor (evaluating 'Object.assign({}, merged, opt)')
TypeError: undefined is not a constructor (evaluating 'Object.assign({}, merged, opt)')
我已经阅读了很多帖子,其中一些是关于 phantomjs 无法与 ES6 一起工作的,但新版本 2.1.1 应该没问题。
我希望有人能指出我正确的方向。
【问题讨论】:
标签: ruby-on-rails webpack rspec capybara poltergeist