Hi,
I’ve created a new Managed Expo project following the Up and Running guide and the app runs, but when I follow the instructions for Testing with Jest the test fails.
I’m new to Expo; I came across the project because a friend is using it in his app and I would like to help him out. I decided to get started by writing tests for the existing code, but ran into issues (more on that another time), so I decided to start a project from scratch and make sure that I understood how to test a Managed Expo project.
I created a new project by following the Up and Running guide and selected the tabs project as suggested. The development server starts correctly and I am able to see the app on my phone using the Android Expo app.
I didn’t make any modifications to the code, I just headed to the section on Testing with Jest and followed those steps. I created the App.test.js unit test and then ran Jest via yarn test
.
However, the test failed with the following:
Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "TypeError: FileSystem.getInfoAsync is not a function
at Asset._downloadAsyncManagedEnv$ (/Users/foo/Code/a-test-expo-app/node_modules/expo-asset/src/Asset.ts:170:30)
at tryCatch (/Users/foo/Code/a-test-expo-app/node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:40)
at Generator.invoke [as _invoke] (/Users/foo/Code/a-test-expo-app/node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:271:22)
at Generator.prototype.(anonymous function) [as next] (/Users/foo/Code/a-test-expo-app/node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:97:21)
at tryCatch (/Users/foo/Code/a-test-expo-app/node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:40)
at invoke (/Users/foo/Code/a-test-expo-app/node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:135:20)
at /Users/foo/Code/a-test-expo-app/node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:170:11
at tryCallTwo (/Users/foo/Code/a-test-expo-app/node_modules/promise/lib/core.js:45:5)
at doResolve (/Users/foo/Code/a-test-expo-app/node_modules/promise/lib/core.js:200:13)
at new Promise (/Users/foo/Code/a-test-expo-app/node_modules/promise/lib/core.js:66:3)".
...
FAIL ./App.test.js
● <App /> › has 1 child
TypeError: Cannot read property 'children' of null
7 | it('has 1 child', () => {
8 | const tree = renderer.create(<App />).toJSON();
> 9 | expect(tree.children.length).toBe(1);
| ^
10 | });
11 | });
at Object.children (App.test.js:9:17) FAIL ./App.test.js
● <App /> › has 1 child
TypeError: Cannot read property 'children' of null
7 | it('has 1 child', () => {
8 | const tree = renderer.create(<App />).toJSON();
> 9 | expect(tree.children.length).toBe(1);
| ^
10 | });
11 | });
at Object.children (App.test.js:9:17)
I can see in node_modules that under the expo-file-system
directory that the TypeScript file exists and the function is defined:
export declare function getInfoAsync(fileUri: string, options?: {
md5?: boolean;
cache?: boolean;
}): Promise<FileInfo>;
Does anyone know why Jest isn’t picking up this definition and how to get a simple test to work with a scaffolded project?
Thanks