-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
Fail to run Jest testing #394
Comments
I don't think there is any. It's also too early for me to invest time in preparing such an example. |
@jpudysz Any suggestions on getting Jest tests configured with the new Unistyles? I am so close 🤏 to upgrading my project to the new arch, and this is the final blocker that I know of. |
Follow errors and try to mock the structure. If you get error from |
Ended up with this: // jest.config.js
module.exports = {
moduleNameMapper: { 'react-native-unistyles': '<rootDir>/__mocks__/react-native-unistyles.js' },
setupFiles: ['<rootDir>/jest.setup.js'],
// ...
}; // jest.setup.js
import './unistyles'; // <-- File that initializes Unistyles // __mocks__/react-native-unistyles.js
// You'll want to edit this mock to fit your use case
let theme;
module.exports = {
UnistylesRuntime: {
hasAdaptiveThemes: false,
setTheme: (newTheme) => {
theme = newTheme;
},
},
StyleSheet: {
configure: (config) => {
theme = config.themes.light;
},
create: (styles) => {
if (typeof styles === 'function') {
return styles(theme);
}
return styles;
},
},
}; |
Thanks @rkrv ! That mock was really helpful to get me started. Once I had that going, I still had to bang my head against a wall for an hour because of this issue: The only way I found to fix it was to disable the unistyles babel plugin during tests 😕 // babel.config.js
module.exports = function (api) {
api.cache(true);
const plugins = [["react-native-unistyles/plugin"]];
// unistyles plugin breaks jest tests
const pluginsDuringTests = [];
return {
presets: ["babel-preset-expo"],
plugins: process.env.NODE_ENV === "test" ? pluginsDuringTests : plugins,
};
}; |
Bumped into this one also. Thanks @rkrv and @remyoudemans. This was resolved by mocking Stylesheet from Unistyles AND the babel plugin changes when |
Description
When I run Jest test suites, I got this error, due to usage under the hood of
react-native-nitro-modules
:Is there any Jest preset to use, I haven't find any in this repo/docs or on react-native-nitro-modules
Steps to Reproduce
react-native-unistyles@beta
yarn expo prebuild --clean
Snack or Repository Link (Optional)
No response
Unistyles Version
3.0.0-beta.1
React Native Version
0.76.3
Platforms
Android, iOS, Web
Expo
Yes
The text was updated successfully, but these errors were encountered: