x-dash
x-dash copied to clipboard
Selecting by class name in unit tests
Because CSS modules are used for x-dash components, the built CSS class names are unpredictable, and so can't (easily) by used as selectors in unit tests, and this is quite limiting.
A couple of possible solutions:
- Turn off class renaming in the build used by the unit tests
- Support importing of the built css and accessing the generated class names (via
classnames?) in the test files
Option 2 would get my vote.
i'm 👍 on option two, but i don't know what if anything would need to change about the jest config to get that working.
With this in x-topic-search/__tests__/x-topic-search.test.js:
import styles from'../dist/TopicSearch.css';
I get this when I run npm test:
[13:20:05] ✖ File to import not found or unreadable: ~@financial-times/x-follow-button/dist/FollowButton.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @financial-times/[email protected] build: `node rollup.js`