The Problem
Using CSS selectors in tests
- Selecting elements via CSS can be brittle. We are selecting elements based on something that could change.
- The purpose of CSS classes are styling, not testing.
Solution:ember-test-selectors
Tell me more...
- Use HTML5 data attributes for your elements
- Provides a testSelector function - you provide a data attribute and it returns the element
- Strips out the attributes on production builds (can override via the build file)
- Does some heavy lifting for data attributes and components for you, just pass a data test attribute and you're done
Example:
This test looks at a collection of usage charges and asserts
Template Changes:
Re-written Test:
0 dependencies on CSS classes!
Summary
- Less brittle tests, since they are no longer dependent on CSS classes
- Can be used with integration or acceptance tests
- Really easy to implement
- Great docs and resources online