question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Render pseudoclass states, so :hover etc can be snapshot-tested

See original GitHub issue

Is your feature request related to a problem? Please describe.

I’m working on a component which I want to have styles that are not overridden by the hosting page. I use snapshots to help with this but am frustrated because snapshots don’t snap the hovered state of components.

For example, I have a grey button which should stay grey when hovered, not turn yellowgreen because some page using the component has decided to import some ugly styles.

image

To ensure my components can’t be overridden like that, I can add some CSS in the preview-header.html to mock the hosting page which has such poor tastes:

button:hover {
background: yellowgreen;
}

and this allows me to confirm if I have a problem via manual inspection (I manually hover over the button and see it is yellowgreen and not grey).

However, I cannot automate this - because Storybook isn’t taking a visual snapshot of the hovered button.

Describe the solution you’d like

I’d love to see something like this addon incorporated into Storybook: https://github.com/Ergosign/storybook-addon-pseudo-states#readme

That addon uses postcss-pseudo-classes under the hood (via a webpack config) to change button:hover { in the CSS to button:hover, button \:hover {, so the Button stories automatically generated can look like <button class="some-selector :hover">howdy</button>. However, I’m using CRA so don’t have the ability to override the webpack config. Would love to know if Storybook could provide better support for such functionality.

Describe alternatives you’ve considered

I’ve also looked at storycap, which allows using a .hover config option that specifies which element should be hovered when a snapshot is taken. However, I’m already using storyshots-puppeteer so I’d like to continue using that.

Are you able to assist bring the feature to reality? Possibly, but I’m not sure where to start.

Additional context Add any other context or screenshots about the feature request here.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:5

github_iconTop GitHub Comments

1reaction
philipponecommented, Jul 4, 2020

I’m developing a add on for this: https://github.com/Ergosign/storybook-addon-pseudo-states

It’s already mentioned in the main post.

I’m thankful for any feedback.

0reactions
a7madgamalcommented, Jul 1, 2020

I’m also looking for this 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hover and focus states • Chromatic docs
Learn how to capture hover and focus states. ... CSS includes the :hover pseudo-class that allow precise styling of an element on cursor...
Read more >
Use with React - Styletron
We can also now use pseudo classes as :hover . The inline styles limitations don't apply anymore! Once the styled component is created,...
Read more >
Snapshot Testing - Jest
Snapshot tests are a very useful tool whenever you want to make sure your UI does not change unexpectedly. A typical snapshot test...
Read more >
Snapshot Testing React Components with Jest - Semaphore CI
render (<App />, div); });. This is not a snapshot test, but it does verify that the test runner (Jest) is working. So,...
Read more >
Testing Universal React (Native) Apps with Jest and Expo!
Here are a few clear examples of problems that will all be missed when using the React Native Jest preset. The Platform API...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found