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.

Snapshots Don't Preserve injected style tags (css-in-js)

See original GitHub issue
  • Operating System: MacOS 10.12.6
  • Cypress Version: 1.4.1
  • Browser Version: Chrome 63

Is this a Feature or Bug? Bug

Current behavior:

My project uses a css-in-js library (in this case cxs) to apply styling. The cxs library appends a style tag to the <head> at runtime and adds style definitions to this injected tag. When tests run normally, styling appears as expected. However, when switching between snapshots, injected style tags (css-in-js) is not preserved and styling is broken on the page

Desired behavior:

Styles should be preserved, or the javascript bundle should be reran so that styles can be injected again.

(although the second option sounds less likely to be reliable given the nature of snapshotting).

How to reproduce:

Run Cypress with a project that uses a css-in-js library that appends a style tags in <head> at run time.

Additional Info (images, stack traces, etc)

(pseudo) DOM structure while tests are running (correct behavior):

<iframe id="Your App: 'my app name'">
  ...
  <head>
    ...
    < !-- style tag injected by cxs -->
    <style id="_cxs_"></style>
    ...
  </head>
  ...
</iframe>

(pseudo) DOM structure while navigating between snapshots after tests have finished:

<iframe id="Your App: 'my app name'">
  ...
  <head>
    ...
    <!-- I did notice that there is still a style tag in the head 
    that _could_ be the injected style tag, but its missing
    its style declarations, and no longer has the `_cxs_` id, so this could just be a red herring -->
    <style></style>
    ...
  </head>
  ...
</iframe>

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
hehex9commented, Apr 9, 2018

I use emotion.js and styling is broken

0reactions
jennifer-shehanecommented, Jan 3, 2020

This issue will be closed to further comment as the exact issue here was resolved and tested.

@jaxxreal If you’re experiencing a bug similar to this in Cypress, please open a new issue with a fully reproducible example that we can run. There may be a specific edge case with the issue that we need more detail to fix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cssinjs/Lobby - Gitter
Anyone has found a good way to have jss styles in a snapshot test? I've found a couple of issues on github but...
Read more >
How to get CSS style in snapshot with Jest - Stack Overflow
I have a React components and I'm using Jest to test it. I want the snapshot to include css style not className. Currently...
Read more >
CSS in React - will-change: transform; | Seifi.org
The automation injects the CSS into the browser for you in a Style tag and attaches the generated className to the HTML element....
Read more >
@konecth/react-snap - npm
Does not depend on React. The name is inspired by react-snapshot but works with any technology (e.g., Vue). npm package does not have...
Read more >
JSS integration with React
Auto attach/detach - sheet will be rendered to the DOM when the component is about to mount, and will be removed when no...
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