I am writing a simple test using react-native-testing-library
(my first steps with that library) in my react native expo app. But I am getting a confused error coming from somewhere inside react-native
code base itself. Either there is something wrong with my code or there is a bug with react-native-testing-library
npm library.
Here is simple jest test:
describe("AppTitle", () => {
it("should display applicaton title", () => {
const { getByText } = render(<AppTitle />);
expect(getByText('App Name')).toBeTruthy();
});
});
And here is the simple <AppTitle />
component (just a View and a Text)
export const AppTitle = () => {
return (
<View>
<Text>App Name</Text>
</View>
);
};
But I am getting this error when I run the test:
...../Utilities/warnOnce.js:15
const warnedKeys: {[string]: boolean} = {};
^^^^^^^^^^
SyntaxError: Missing initializer in const declaration
at ScriptTransformer.transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:471:17)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:513:25)
at Object.<anonymous> (node_modules/react-native/Libraries/react-native/react-native-implementation.js:14:18)
...
This is a simple and straight forward template. Any help from a react-native + react-native-testing-library would be appreciate.
Expo 33
The "Missing initializer in const declaration" error occurs when a variable is declared using const , but its value is not initialized on the same line. To solve the error, initialize the variable on the same line you declare it, e.g. const num = 30; .
Constants are block-scoped, much like variables declared using the let keyword. The value of a constant can't be changed through reassignment (i.e. by using the assignment operator), and it can't be redeclared (i.e. through a variable declaration).
I resolved this added "preset": "react-native" in jest.config.js file
I am using expo in my project. I have same issue. i forgot to add "preset": "jest-expo" to package.json. i added then the problem solved.
"jest": { "preset": "jest-expo" },
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