I'm going to create snapshot test, but got problems in the beginning.
I got such error while running test:
/Users/illia/WebstormProjects/TESTS/node_modules/jest/node_modules/jest-cli/build/cli/index.js:161
if (error?.stack) {
^
SyntaxError: Unexpected token '.'
In the test file I have no errors
import renderer from 'react-test-renderer';
import PaymentDisclaimer from './PaymentDisclaimer';
it('renders correctly when all default props', () => {
const tree = renderer.create(<PaymentDisclaimer fullPrice={9} />).toJSON();
expect(tree).toMatchSnapshot();
});
Packages:
"react-test-renderer": "^18.2.0",
"jest": "^29.0.3",
"ts-jest": "^29.0.1", (was installed as possible solution)
This happens when jest is running under the node version that do not read the new updates from JS. You need to run it in node 14 or higher.
Specifically, the ?. in if (error?.stack) is an optional chaining operator which is only supported in versions 14 or higher.
You can switch Node version using nvm:
$ nvm use 14
Now using node v14.18.0 (npm v6.14.15)
check Node Version Manager (nvm)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With