我得到的RSpec +水豚+吵鬧鬼以下錯誤:水豚迫不及待Ajax請求
given!(:user_owner) { create(:user) }
given!(:second_user) { create(:user) }
given!(:question) { create(:question, user: user_owner) }
describe 'as not question owner' do
before do
login_as(second_user, scope: :user, run_callbacks: false)
visit question_path(question)
end
scenario 'can upvote just one time', js: true do
first('a#question-upvote').click
expect(first('div#question-score').text).to eq '1'
first('a#question-upvote').click
expect(first('div#question-score').text).to eq '1'
end
故障/錯誤:期待(page.first( '#DIV問題 - 得分')文本。)。爲了EQ '-1'
expected: "-1"
got: "0"
當我插入睡眠1:
scenario 'can upvote just one time', js: true do
first('a#question-upvote').click
sleep 1
expect(first('div#question-score').text).to eq '1'
first('a#question-upvote').click
sleep 1
expect(first('div#question-score').text).to eq '1'
end
試驗合格。
我明白了頁面沒有異步請求。 如何重寫測試以使其在沒有睡眠的情況下正常工作?
P.S.對不起英文。
謝謝Thomas。你再次幫助我。 –