Giter Club home page Giter Club logo

Comments (9)

3210jr avatar 3210jr commented on May 24, 2024 2

@GiaHuy216 - I just got my tests to work again, had to remove: testEnvironment: "jsdom", as suggested by @frankcalise and then replaced the transform, here is what I have now as my jest.config.js (including commented out code):

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

from ignite.

frankcalise avatar frankcalise commented on May 24, 2024

Hi @GiaHuy216

I couldn't reproduce that error exactly, but had run into the test just never completing until I removed testEnvironment: "jsdom" from the jest config. Then the test provided worked as is.

Could you paste your Profile component here as well?

from ignite.

markrickert avatar markrickert commented on May 24, 2024

This also might happen if you file is named .js or .ts instead of .jsx/.tsx. The "X" in the file name indicated that the compiler should expect XML in the javascript

from ignite.

GiaHuy216 avatar GiaHuy216 commented on May 24, 2024

@frankcalise
Here is Profile component

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 testEnvironment: "jsdom" like you said but it doesn't work .Did i miss something?

from ignite.

GiaHuy216 avatar GiaHuy216 commented on May 24, 2024

@markrickert My component file and test file are both tsx files.

from ignite.

frankcalise avatar frankcalise commented on May 24, 2024

@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

from ignite.

frankcalise avatar frankcalise commented on May 24, 2024

I can't reproduce this in the latest Ignite, @GiaHuy216 are you still experiencing issues?

from ignite.

GiaHuy216 avatar GiaHuy216 commented on May 24, 2024

@3210jr After I copied your jest.config.js file and it worked perfectly,thank you.

from ignite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.