sveltekit - 如何在 Sveltekit 中用 __mocks__ 替换函数?
问题描述
我的目标是为我的打字稿功能编写高效的单元+集成测试。每个应该被模拟的函数都有一个__mocked__
文件夹和一个匹配的文件名。因为我在配置 Sveltekit 时不知道怎么做,所以我目前在代码库中这样做:
export async function updateAuth0User(opts: any) {
if (config.isTest) {
// TODO One day would be nice if we could avoid this...
const { updateAuth0User } = await import('./__mocks__/update-auth0-user');
// @ts-ignore
return updateAuth0User.apply(this, arguments);
}
// actual implementation, when not running tests;
}
以上可以自动完成,所以我可以避免config.isTest
污染我的代码吗?
提前谢谢☺️
解决方案
推荐阅读
- mysql - BEGIN...COMMIT vs LOCK TABLES
- python - 使用 discord.py 的一个命令允许多个角色
- c# - Xamarin 模拟器 - 系统 UI 没有响应
- ios - 向 Ionic 4 项目添加 cordova-plugin-firebase-dynamiclinks 导致无法构建
- three.js - 将 DeviceOrientationControls 添加到 GLTF GLB 对象
- java - 为什么 System.getProperty("java.io.tmpdir") 在 Mac OS X Catalina 10.15 上返回只读目录
- python - 使用 BeautifulSoup 抓取 OSHA 网站
- python - 双曲曲线_拟合的预测区间 - SciPy
- php - 处理 PHP 多维数组以将键分配为值数组的父级
- r - stringr: how to recover sentences from a string that was derived from concatenating those sentences