I'm trying to test the onPress event inside this screen:
const MyScreen = () => {return (<View><Button title="Confirm" onPress={()=>console.log('a')}/> </View>)}
Here the test:
`
describe("Test", () => {const enzyme = require('enzyme');const wrapper = enzyme.shallow(<MyScreen/>);wrapper.find(Button).prop("onPress")!({} as any);});
But I get:
● Test suite failed to run
Jest encountered an unexpected tokenJest 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.Details:/MyProject/src/test/myTest.test.tsx:11 const wrapper = enzyme.shallow(<MyScreen_1.default />); ^SyntaxError: Unexpected token '<' at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1479:14)
my test.config.jsis
module.exports = {preset: "ts-jest","roots": ["<rootDir>/src"],"testMatch": ["**/__tests__/**/*.+(ts|tsx|js)","**/?(*.)+(spec|test).+(ts|tsx|js)"],transform: {"^.+\\.(js|ts)$": "ts-jest",},testEnvironment: 'jsdom',"snapshotSerializers": ["enzyme-to-json/serializer"],"moduleFileExtensions": ["ts","tsx","js","jsx","json","node"], globals: {"ts-jest": { tsconfig: { allowJs: true, }, },}}
Anyone has a clue about what could be wrong?
And if I have more buttons, how could I trigger onPress for the right one?