jaredlunde / jest-stitches Goto Github PK
View Code? Open in Web Editor NEWJest utilities for Stitches
Home Page: https://npmjs.com/package/jest-stitches
License: MIT License
Jest utilities for Stitches
Home Page: https://npmjs.com/package/jest-stitches
License: MIT License
Describe the bug
I'm adding this as a bug rather than a feature request as this behaviour has changed when upgrading to the latest beta version of stitches. Previously jest-stitches
would collate all the relevant classes and render them in the snapshot but would not include the :root
pseudo-class containing the stitches theme, I think this is the correct behaviour as :root
level custom properties are not specific to the component.
To Reproduce
Create a generic styled
component from stitches alongside a test using jest-stitches
import { createCss } from '@stitches/react'
const { styled } = createCss({
theme: {
colors: { primary: 'red' }
}
})
export const Box = styled('div', {})
import { render, screen } from '@testing-library/react'
import * as React from 'react'
import { Box } from './'
describe(`Box component`, () => {
it('renders', async () => {
const { container } = render(
<Box css={{ color: '$primary' }}>BOX</Box>
)
await screen.findByText('BOX')
expect(container).toMatchSnapshot()
})
})
jest.config.js
module.exports = {
snapshotSerializers: ['jest-stitches']
}
Expected behavior
Expect to see relevant classes from styled
component and css
, but not document level :root
class.
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Box component renders 1`] = `
:root {
--colors-primary: red;
}
.sx03kze4nwvh--css {
color: var(--colors-primary);
}
<div>
<div
class="sx03kze sx03kze4nwvh--css"
>
BOX
</div>
</div>
`;
Additional context
Package versions
"@stitches/react": "0.1.0-canary.3",
"jest": "26.6.3",
"jest-dom": "4.0.0",
"jest-stitches": "1.0.4"
Let me know if you need any additional context or detail with the issue, thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.