javascript - Proxyquire 显示错误“找不到模块”
问题描述
我正在尝试使用proxyquire替换私有函数以在我的 Meteor 应用程序中进行测试。
流星 1.6.1
流星测试:mocha@1.1.2
在我的 parentFunction.js 中:
import { some function } from 'anotherFile';
function childFunction() {
...
return someValue;
}
export default function parentFunction() {
return childFunction()
}
在我的测试文件中:
const proxyquire = require('proxyquire');
if (Meteor.isServer) {
...
describe('parentFunction', () => {
it('uses the mocked child function', () => {
const testThing = proxyquire('./parentFunction', {
'childFunction': () => ({ 'name': 'bob' }),
});
});
}
parentFunction.js 与我的测试文件在同一个文件夹中,只是为了仔细检查路径,我确保它有效:
import parentFunction from './parentFunction';
但是当我运行测试时,我看到了一个错误:
Error: Cannot find module './parentFunction.js'
我究竟做错了什么?我试过绝对路径,没用。据我从文档中可以看出,文件中需要 proxiquire 的相对路径应该没问题。
谢谢你的帮助!
解决方案
推荐阅读
- r - R 插入符号:结合 rfe() 和 train()
- c# - 如何在 ASP.NET Core 2.1 网站上启用 HttpOnly cookie
- .net - 如何使用“DetectLocalizedObjects”?
- codeigniter - codeigniter 在单独的字段中上传 2 个文件(图像和视频)
- html - 使用uikit的图像叠加悬停效果
- java - 通过 EventChannel 向 Flutter 发送 Android SMS BroadcastReceiver 数据
- jquery - 选中父复选框时,仅检查没有子子项的直接子项
- c# - 如何在asp net core中的服务之间共享websocket
- android - Android UDP 故障导致 VOIP 口吃
- java - 拥有@ApplicationScoped bean 效率更高吗?