Closed tkyr-hh closed 7 months ago
@tkyr-hh Did you added the required import to your jest-setup.ts
file? https://callstack.github.io/react-native-testing-library/docs/jest-matchers#setup
@mdjastrzebski yes, I've add it inside under the jest key in package.json as setupFilesAfterEnv
.
"jest": {
"preset": "react-native",
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?@react-native|react-native|@react-native/.*|@sentry/react-native|@react-navigation/.*|react-native-svg|@sentry/react-native|react-native-appsflyer|@react-native-community/.*|@react-native-community/geolocation)"
],
"setupFilesAfterEnv": [
"@testing-library/jest-native/extend-expect"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"automock": false,
"setupFiles": [
"./node_modules/react-native-gesture-handler/jestSetup.js",
"./setup-jest.js"
],
"transform": {
"^.+\\.js?$": "babel-jest"
}
}
/* eslint-env jest */
import {NativeModules} from 'react-native';
import 'react-native-gesture-handler/jestSetup';
NativeModules.ImagePickerManager = {
showImagePicker: jest.fn(),
launchCamera: jest.fn(),
launchImageLibrary: jest.fn(),
};
...
You should be importing "@testing-library/react-native/extend-expect"
, and not "@testing-library/jest-native/extend-expect"
.
You have this in your jest
entry in package.json
:
"setupFilesAfterEnv": [
"@testing-library/jest-native/extend-expect"
],
Oh! sorry, I ready did not noticed this difference while I am setting up the testing environment. @mdjastrzebski Thanks a lot for your help.
Closing this issue...
Describe the bug
As mentioned in the docs we can check the TextInput value with native matcher toHaveDisplayValue(value)
Expected behavior
The matcher is working fine.
Steps to Reproduce
const textInput = screen.getByPlaceholderText('mobile Number'))
expect(textInput).toHaveDisplayValue(/^5[0-9]{8}$/);
.Versions