Open GiaHuySE opened 10 months ago
'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
import React from "react"
import { fireEvent, render, screen } from "@testing-library/react-native"
import { Profile } from "../Profile"
describe("Profile", () => {
it("renders", () => {
render(<Profile />)
expect(screen.getByText("Hello")).toBeTruthy()
})
})
I followed https://reactnativetesting.io/component/setup/ in order to install @testing-library/react-native but now I'm getting
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
/Users/giahuy/PizzaApp/app/components/specs/Profile.spec.tsx:12
(0, react_native_1.render)(<Profile_1.Profile />);
^
SyntaxError: Unexpected token '<'
Here my jest.config.js
const { defaults: tsjPreset } = require("ts-jest/presets")
/** @type {import('@jest/types').Config.ProjectConfig} */
module.exports = {
...tsjPreset,
preset: "react-native",
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"],
testEnvironment: "jsdom",
setupFiles: ["<rootDir>/test/setup.ts"],
transform: {
"^.+\\.spec.tsx?$": [
"ts-jest",
{
tsconfig: "<rootDir>/test/test-tsconfig.json",
},
],
},
}
how can I fix it ??
System
platform darwin
arch arm64
cpu 8 cores Apple M2
directory PizzaApp /Users/giahuy/PizzaApp
JavaScript (and globally-installed packages)
node 18.18.2 /Users/giahuy/.nvm/versions/node/v18.18.2/bin/node
npm 9.8.1 /Users/giahuy/.nvm/versions/node/v18.18.2/bin/npm
corepack 0.19.0
npm 9.8.1
yarn 1.22.21 /opt/homebrew/bin/yarn
create-jest 29.7.0
pnpm - not installed
bun - not installed
expo 49.0.21 managed
Ignite
ignite-cli 9.3.1 /Users/giahuy/.npm/_npx/e31027f3785124a8/node_modules/.bin/ignite
ignite src build /Users/giahuy/.npm/_npx/e31027f3785124a8/node_modules/ignite-cli/build
Android
java 17.0.9 /usr/bin/java
android home - /Users/giahuy/Library/Android/sdk
iOS
xcode 15.1
cocoapods 1.14.3 /opt/homebrew/bin/pod
Tools
git git version 2.39.3 (Apple Git-145) /usr/bin/git
i also removed testEnvironment: "jsdom"