x-dash icon indicating copy to clipboard operation
x-dash copied to clipboard

Selecting by class name in unit tests

Open dan-searle opened this issue 6 years ago • 2 comments

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:

  1. Turn off class renaming in the build used by the unit tests
  2. Support importing of the built css and accessing the generated class names (via classnames?) in the test files

Option 2 would get my vote.

dan-searle avatar Jan 30 '19 11:01 dan-searle

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.

apaleslimghost avatar Feb 05 '19 12:02 apaleslimghost

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`

dan-searle avatar Feb 05 '19 13:02 dan-searle