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

时间:2019-03-26 10:03:13

标签: javascript testing meteor mocha proxyquire

我正在尝试使用proxyquire代替私有功能以在我的Meteor应用中进行测试。

流星1.6.1

meteortesting: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的相对路径应该没问题。

感谢您的帮助!

0 个答案:

没有答案
相关问题