styled-components / jest-styled-components

🔧 💅 Jest utilities for Styled Components
MIT License
1.58k stars 144 forks source link

Doesn't seem to support Jest 28.x.x #414

Closed Lkleven closed 1 year ago

Lkleven commented 1 year ago

Hi, I have tried upgrading Jest from 27 to 28 and it seems that jest-styled-components doesn't do anything after the upgrade.

I have code similar to your examples

import React from 'react';
import { render } from '@testing-library/react';
import 'jest-styled-components';
import styled from 'styled-components';

const Button = styled.button`
  color: yellow;
`;

describe('Test', () => {
  it('works', () => {
    const { container } = render(<Button />);
    expect(container.firstChild).toMatchSnapshot();
  });
});

But the snapshot still have the dynamic classname from styled-components and doesn't include the actual styles:

exports[`Test works 1`] = `
<button
  class="sc-bczRLJ bqIyce"
/>

Any input on this would be greatly appreciated.

kungfutse commented 1 year ago

Same thing with Jest 29

dylang commented 1 year ago

I was able to work around this by changing the test running from testRunner: "jest-jasmine2" to the default. I don't know why this fixes it.

Lkleven commented 1 year ago

I was able to work around this by changing the test running from testRunner: "jest-jasmine2" to the default. I don't know why this fixes it.

I already used the default testRunner jest-circus/runner so i figured i might as well try and change to jest-jasmine2, and it actually works. Not really sure why though.

Closing the issue for now as it seems to be testRunner related

buugaaga commented 1 year ago

This issue is not resolved. Need to update jest version in dependencies.

daraclare commented 1 year ago

I'm having this issue with Jest 28 and 29,changing the runner doesn't help. Can this be reopened?

mmakarin commented 1 year ago

Same here