From 43377979c6cfee922702a5dc6324fded96b1f111 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 16 Oct 2017 12:37:52 -0500 Subject: Check for element before evaluate_script Tip from https://robots.thoughtbot.com/write-reliable-asynchronous-integration-tests-with-capybara#directly-interacting-with-javascript --- doc/development/testing_guide/best_practices.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'doc/development/testing_guide') diff --git a/doc/development/testing_guide/best_practices.md b/doc/development/testing_guide/best_practices.md index 613423dbd9a..7ddd02e6c73 100644 --- a/doc/development/testing_guide/best_practices.md +++ b/doc/development/testing_guide/best_practices.md @@ -35,6 +35,8 @@ Here are some things to keep in mind regarding test performance: [Gotchas](../gotchas.md#dont-assert-against-the-absolute-value-of-a-sequence-generated-attribute)). - Don't supply the `:each` argument to hooks since it's the default. - On `before` and `after` hooks, prefer it scoped to `:context` over `:all` +- When using `evaluate_script("$('.js-foo').testSomething()")` (or `execute_script`) which acts on a given element, + use a Capyabara matcher beforehand (e.g. `find('.js-foo')`) to ensure the element actually exists. [four-phase-test]: https://robots.thoughtbot.com/four-phase-test -- cgit v1.2.1