Proxyquire 显示错误“找不到模块”

Lit*_*ain 6 javascript testing mocha.js meteor 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()
}
Run Code Online (Sandbox Code Playgroud)

在我的测试文件中:

const proxyquire = require('proxyquire');

if (Meteor.isServer) {
  ...

  describe('parentFunction', () => {
    it('uses the mocked child function', () => {
      const testThing = proxyquire('./parentFunction', {
        'childFunction': () => ({ 'name': 'bob' }),
      });
  });
}
Run Code Online (Sandbox Code Playgroud)

ParentFunction.js 与我的测试文件位于同一文件夹中,为了仔细检查路径,我确保它有效:

import parentFunction from './parentFunction';
Run Code Online (Sandbox Code Playgroud)

但是当我运行测试时,我看到一个错误:

Error: Cannot find module './parentFunction.js'
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?我试过绝对路径,没用。据我从文档中看到,需要 proxiquire 的文件中的相对路径应该没问题。

谢谢你的帮助!