我正在尝试为我的小项目编写一些测试。我们使用了expo-file-system来访问IOS内部存储。这是我对保存功能的测试。

import SaveData from "../app/resources/SaveData/SaveData"
import * as FileSystem from 'expo-file-system';

var promiseHolder = 0;

describe('\nsaveNewFile() is tested.\n', ()=>{
it("A file is going to be created.",async ()=>{
    await FileSystem.writeAsStringAsync("sometext","test.txt");
    promiseHolder = await FileSystem.getInfoAsync("test.txt");
    testHolder = await FileSystem.readAsStringAsync("test.txt");
    console.log(promiseHolder)
    console.log(testHolder)
  });
});


这是输出。
Command line output

看来FileSystem.documentDirectory在测试中无法正常工作,但我们的应用程序运行良好。我该怎么办?

最佳答案

您没有像testHolder那样声明testHolder变量。

 import SaveData from "../app/resources/SaveData/SaveData";
 import * as FileSystem from 'expo-file-system';

 var promiseHolder = 0;
 var testHolder = 0;

describe('\nsaveNewFile() is tested.\n', ()=>{
it("A file is going to be created.",async ()=>{
   await FileSystem.writeAsStringAsync("sometext","test.txt");
   promiseHolder = await
   FileSystem.getInfoAsync("test.txt");
   testHolder = await FileSystem.readAsStringAsync("test.txt");
   console.log(promiseHolder)
   console.log(testHolder)
    });
 });

关于ios - 为什么expo-FileSystem在Jest中不起作用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58262638/

10-12 04:38