-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
SyntaxError: Unexpected token '<' when running Jest #2605
Comments
Hi @GiaHuy216 I couldn't reproduce that error exactly, but had run into the test just never completing until I removed Could you paste your |
This also might happen if you file is named |
@frankcalise import * as React from "react"
import { StyleProp, TextStyle, View, ViewStyle } from "react-native"
import { observer } from "mobx-react-lite"
import { colors, typography } from "app/theme"
import { Text } from "app/components/Text"
export interface ProfileProps {
/**
* An optional style override useful for padding & margin.
*/
style?: StyleProp<ViewStyle>
}
/**
* Describe your component here
*/
export const Profile = observer(function Profile(props: ProfileProps) {
const { style } = props
const $styles = [$container, style]
return (
<View style={$styles}>
<Text style={$text}>Hello</Text>
</View>
)
})
const $container: ViewStyle = {
justifyContent: "center",
}
const $text: TextStyle = {
fontFamily: typography.primary.normal,
fontSize: 14,
color: colors.palette.primary500,
} I also removed |
@markrickert My component file and test file are both tsx files. |
@GiaHuy216 - I just got my tests to work again, had to remove: const { defaults: tsjPreset } = require("ts-jest/presets")
/** @type {import('@jest/types').Config.ProjectConfig} */
module.exports = {
...tsjPreset,
preset: "jest-expo",
transformIgnorePatterns: [
"<rootDir>/node_modules/(react-clone-referenced-element|@react-native-community|react-navigation|@react-navigation/.*|@unimodules/.*|native-base|react-native-code-push)",
"jest-runner",
],
testPathIgnorePatterns: ["<rootDir>/node_modules/", "<rootDir>/.maestro/", "@react-native", "<rootDir>/test/i18n.test.ts"],
// testEnvironment: "jsdom",
setupFiles: ["<rootDir>/test/setup.ts"],
"setupFilesAfterEnv": [
"@testing-library/jest-native/extend-expect"
],
coverageDirectory: "<rootDir>/test/coverage",
collectCoverageFrom: [
"**/*.{js,jsx,ts,tsx}",
"!**/node_modules/**",
"!**/vendor/**",
"!**/test/**",
"!**/coverage/**",
"!**/.expo/**",
"!**/android/**",
"!**/ios/**",
],
// moduleNameMapper: {
// "app/(.*)": "<rootDir>/app/$1",
// },
transform:{
// '^.+\\.test.tsx?$': ['ts-jest', {
// tsconfig: '<rootDir>/test/test-tsconfig.json'
// }],
"^.+\\.[jt]sx?$": "babel-jest",
},
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
"globals": {
"ts-jest": {
"diagnostics": false
}
}
} Let me know if this works, or causes other issues I haven't come across yet |
@3210jr thanks for confirming it's working. it also aligns with what I found here on RNTL's issue board: callstack/react-native-testing-library#896 (comment) Will make that update to the boilerplate |
I can't reproduce this in the latest Ignite, @GiaHuy216 are you still experiencing issues? |
@3210jr After I copied your jest.config.js file and it worked perfectly,thank you. |
🎉 This issue has been resolved in version 9.6.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Describe the bug
I'm using ignite to create an expo react native app. I'm using this guide https://ignitecookbook.com/docs/recipes/GeneratorComponentTests to create component test files
Here is the first test file
I followed https://reactnativetesting.io/component/setup/ in order to install @testing-library/react-native but now I'm getting
Here my jest.config.js
how can I fix it ??
Ignite version
9.3.1
Additional info
The text was updated successfully, but these errors were encountered: