HarmonyOS 鸿蒙Next mock模块但是出现pick is not initialized
HarmonyOS 鸿蒙Next mock模块但是出现pick is not initialized
使用mock模块的功能
import pick from '[@ohos](/user/ohos).file.picker';
import { generateRandomFilename } from '../../../main/ets/common/utils/galleryUtil';
class PhotoViewPicker {
select(options: pick.PhotoSelectOptions): Promise<pick.PhotoSelectResult> {
return Promise.resolve({
photoUris: [generateRandomFilename('jpg')],
isOriginalPhoto: true,
} as pick.PhotoSelectResult);
}
}
const MockPick: Record<string, Object> = {
'PhotoViewPicker': PhotoViewPicker,
'PhotoSelectOptions': pick.PhotoSelectOptions,
'PhotoViewMIMETypes': pick.PhotoViewMIMETypes,
};
export default MockPick;
在test coverage的时候报错: Error message:pick is not initialized SourceCode: ‘PhotoSelectOptions’: pick.PhotoSelectOptions, ^ Stacktrace: SourceMap is not initialized yet at func_main_0 (entry/src/mock/modules/ohos/mock-picker.ets:124:25)
但是我正常运行test就没有问题, 这个问题出现在test coverage
我的配置跟 文档中描述的一致
"[@ohos](/user/ohos).file.picker": {
"source": "src/mock/modules/ohos/mock-picker.ets"
}
更多关于HarmonyOS 鸿蒙Next mock模块但是出现pick is not initialized的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
import { PhotoViewPicker } from ‘./path-to-your-module’;
import * as pick from ‘@ohos.file.picker’;
describe(‘PhotoViewPicker’, () => {
it(‘should select photo correctly’, () => {
const picker = new PhotoViewPicker();
const options = new pick.PhotoSelectOptions();
return picker.select(options).then(result => {
expect(result.photoUris).toHaveLength(1);
expect(result.isOriginalPhoto).toBe(true);
});
});
});
更多关于HarmonyOS 鸿蒙Next mock模块但是出现pick is not initialized的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
针对您提到的HarmonyOS鸿蒙系统中Next mock模块出现的“pick is not initialized”问题,这通常是因为mock模块或相关依赖未正确初始化或配置。请检查以下几点:
- 确保所有相关的mock库和依赖都已正确安装并导入到您的项目中。
- 检查mock模块的初始化代码是否已执行,并放在合适的位置(如应用启动时)。
- 查看是否有任何配置遗漏或错误,如配置文件中的mock设置。
如果问题依旧没法解决请加我微信,我的微信是itying888。
更多关于HarmonyOS 鸿蒙Next mock模块但是出现pick is not initialized的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html