Is it possible to test existance of js function in page using Capybara? if so, can I make a call and check result?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Capybara is used to test the overall functionality of your web application by actually rendering the page. When you are using an engine that can execute Javascript (the default Rack::Test engine does not), you can use it to check that your page is indeed rendered correctly after executing the relevant Javascript. There are ways to test a function’s existence by calling
page.execute_script("typeof yourFunctionName == 'function'")(and only select engines support this) and check its value but know that Capybara it is not designed to be a Javascript test framework. You should use Jasmine for that.