-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Invalid value for prop css
on <div> tag when running Jest
#1759
Comments
Most likely you have forgotten to use jsx pragma ( |
I thought this wasn't necessary when using the emotion/babel-preset-css-prop Babel config? |
In that case - yes, it shouldnt be needed. For some reason though it hasnt transformed your css prop. You would have to share a runnable repro case so I could take a look at your setup |
Closing this because a runnable repro case has not been provided so far. |
@ngmiduc I'm afraid that you have configured something wrongly with the regards to {
cwd: '/Users/mateuszburzynski/Desktop/react-jest-emotion-error',
filename: '/Users/mateuszburzynski/Desktop/react-jest-emotion-error/src/App.js',
options: {
presets: [
'/Users/mateuszburzynski/Desktop/react-jest-emotion-error/node_modules/babel-preset-react-app/index.js',
'/Users/mateuszburzynski/Desktop/react-jest-emotion-error/node_modules/babel-preset-jest/index.js'
],
plugins: [],
babelrc: true,
caller: { name: 'babel-jest', supportsStaticESM: false },
compact: false,
sourceMaps: 'both'
}
} and as you may notice |
Oh yes, I see. |
How can you get the babel config that is passed to the jest env ? |
I have no idea how to do this when using |
@ngmiduc did you get lucky with this? I am having the same issue using my
my
@Andarist how can I see what is being past to the plugin? I use CRA which makes the custom config all a bit too elaborate. I will be super grateful for any help. Many thanks! 🙏🏻 |
Sorry, no - I hadn't time to look at it further. |
I actually managed to get it recognised by jest when running
Ideas how to fix that? |
Inspect the stack trace that leads to this error and you should be able to see which style leads to this. How to fix the problem is mentioned in this message - unless you are suffering from some different problem and used heuristics are not 100% accurate. |
@Andarist So the problem actually is with my custom component library that I build and plugin to my project where when I then run Jest it complains. It's not a problem when running or building the consuming application, it's only a problem when trying to test it. I managed to get Jest to use my
I still have those two errors (in Jest only) - when I import a component from my built library it gives me the 'string literal error' and when I use emotion css prop on in the consuming application I get the 'invalid prop error'. I do have the latest babel-css-prop plugin (11.2.0) |
Well, this is really not a lot of information to debug this properly. Please always try to share a repro case in a runnable form - either by providing a git repository to clone or a codesandbox. OSS maintainers usually can't afford the time to set up the repro, even if exact steps are given. |
My project has worked well with the following setup. // jest.config.js
module.exports = {
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
// Add more setup options before each test is run
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/.next/'],
testEnvironment: 'jest-environment-jsdom',
transform: {
// Use babel-jest to transpile tests with the next/babel preset
// https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object
'^.+\\.(js|jsx|ts|tsx)$': [
'babel-jest',
{
presets: [
[
'next/babel',
{
'preset-react': {
runtime: 'automatic',
importSource: '@emotion/react',
},
},
],
],
plugins: ['@emotion/babel-plugin'],
},
],
},
transformIgnorePatterns: [
'/node_modules/',
'^.+\\.module\\.(css|sass|scss)$',
],
}; Environment information:
|
Current behavior:
When running tests via Jest, I receive the following warning dozens of times in our output:
To reproduce:
The pertinent part of the code is here:
Expected behavior:
I would expect that the CSS prop shouldn't throw an Unknown Prop warning: https://reactjs.org/warnings/unknown-prop.html
Environment information:
react
version: 16.9.0react-dom
version: 16.9.0emotion-core
version: 10.0.27emotion
version: 10.0.27jest
version 23.6.0,jest-emotion
version 10.0.7aThe text was updated successfully, but these errors were encountered: