Skip to content

Please consider wrapping the added style string in <style> element #135

Description

@larsno

Currently the styles are added to the snapshot string as if writing to a CSS file. However the snapshot file really represents a HTML and so the styles should reside inside a <style> element.

This means a snapshot file can be viewed in a browser as something like:
image
instead of text with the raw CSS prepended.

This can be simply done by replacing the line:

    let result = `${style}${style ? '\n\n' : ''}${code}`

in the file styleSheetSerializer.js with this line:

    let result = `${style ? '<style>\n' : ''}${style}${style ? '\n</style>\n\n' : ''}`

Even better, if the snapshotSerializer jest-html is ordered after jest-styled-components then the styled-components CSS will be included in its preview. (Unfortunately I can't get the jest-html serializer to happen after the jest-styled-component serializer. Any ideas?)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions