Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vitest 3 causes emotion ThemeProvider tests to fail #7334

Closed
6 tasks done
bmcallis opened this issue Jan 22, 2025 · 2 comments
Closed
6 tasks done

vitest 3 causes emotion ThemeProvider tests to fail #7334

bmcallis opened this issue Jan 22, 2025 · 2 comments

Comments

@bmcallis
Copy link

Describe the bug

After updating to vitest@3 our tests using ThemeProvider from @emotion/react and rendering components with @testing-library/react are failing because the theme object that gets passed to the component is an empty object. The tests work fine with vitest@2 and render correctly in the browser.

Reproduction

Here is a simple example of the issue

import React from 'react';
import { describe, expect, it } from 'vitest';
import { ThemeProvider } from '@emotion/react';
import styled from '@emotion/styled';
import { render } from '@testing-library/react';

const theme = {
  colors: {
    primary: 'hotpink',
  },
};

const SomeText = styled.div`
  color: ${(props) => {
    console.log('SomeText theme', props.theme);
    return props.theme.colors.primary;
  }};
`;


describe('ColorGrid', () => {
  it('Should render themed text with wrapper', () => {
    const { container } = render(<SomeText />, { wrapper: (props) => (<ThemeProvider theme={theme} {...props} />) });
    expect(container).toMatchSnapshot();
  });

  it('Should render themed text with inline provider', () => {
    const { container } = render(<ThemeProvider theme={theme}><SomeText /></ThemeProvider>);
    expect(container).toMatchSnapshot();
  });
});

And there is a minimal repo to reproduce the issue here: https://gitlab.com/bmcallis/vitest-bug

System Info

System:
    OS: macOS 15.2
    CPU: (12) arm64 Apple M2 Max
    Memory: 15.05 GB / 96.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.12.0 - ~/.nvm/versions/node/v22.12.0/bin/node
    npm: 11.0.0 - ~/.nvm/versions/node/v22.12.0/bin/npm
  Browsers:
    Chrome: 131.0.6778.265
    Safari: 18.2
  npmPackages:
    vite: ^6.0.10 => 6.0.10
    vitest: ^3.0.2 => 3.0.2

Used Package Manager

npm

Validations

@hi-ogawa
Copy link
Contributor

This looks like a duplicate of #7070 (comment) though it's probably more complicated.

@emotion/xxx packages uses development and module conditions https://publint.dev/@emotion/[email protected], but Vitest 3 dropped both. I actually don't understand why this would break @emotion/xxx since they seems to be functional on plain Node, which doesn't have neither of development and module. https://stackblitz.com/edit/vitest-dev-vitest-whbrjxfd?file=repro.js

Nonetheless, adding resolve.conditions: ['node', 'development'] fixes the repro, so this will be probably fixed by #7301

@bmcallis
Copy link
Author

This was fixed by 3.0.4. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants